// Problem: C. Lorenzo Von Matterhorn
// Contest: Codeforces - Codeforces Round #362 (Div. 2)
// URL: https://codeforces.com/contest/697/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 2022-03-02 21:02:59
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define mp make_pair
const ll mod = 1e9 + 7;
inline ll qmi (ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1) ans = ans * a%mod;
a = a * a %mod;
b >>= 1;
}
return ans;
}
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
inline ll sub (ll a, ll b) {
return ((a - b ) %mod + mod) %mod;
}
inline ll add (ll a, ll b) {
return (a + b) %mod;
}
inline ll inv (ll a) {
return qmi(a, mod - 2);
}
#define int long long
const int N = 5050;
int dp[N][N];
int n;
int a[N];
void solve() {
cin >> n;
rep(i, 1, n ) cin >> a[i];
for (int i = 1; i <= n ; i ++) {
memcpy(dp[i], dp[i - 1], sizeof dp[0]);
dp[i][a[i]] ++;
}
for (int i = 1; i <= n; i ++) {
for (int j = n; j >= 1; j --)
dp[i][j] += dp[i][j + 1];
}
int mx1 = 0,mx2 = 0;
for (int i =1; i <= n ; i++) {
for (int j = i + 1; j <= n ;j ++) {
if (a[i] <= a[j]) continue;
int cnt = 2 * (dp[j - 1][a[j] + 1] - dp[j - 1][a[i]] - (dp[i][a[j] + 1] - dp[i][a[i]])) + 1;
if (cnt == mx2) {
mx1++;
}
else if (cnt > mx2) {
mx2 = cnt, mx1 = 1;
}
}
}
if (mx2) {
int tot = -mx2;
for (int i = 1; i <= n ;i ++)
tot += dp[i][a[i] + 1];
cout << tot << " " << mx1 <<endl;
}
else {
cout << 1 << ' ' << n * (n - 1) / 2 << endl;
}
}
signed main () {
int t;
t =1;
while (t --) solve();
return 0;
}
用dp[i][j]表示1~i >= a[j]的a[i]个数。 对于(i, j) i < x < j 交换后a[j]的逆序对减少k + 1,每一个a[x]减少1.总共2*k+1