const int maxn = 5002; int num[maxn]; int sum[maxn][maxn];//sum[i][j] means in range i+1~j there are sum[i][j] numbers are smaller than num[i]; int sum1[maxn][maxn];//sum[i][j] means in range i+1~j there are sum[i][j] numbers are smaller than num[j]; int main() { //freopen("in.txt","r",stdin); int n; while(cin>>n) { repf(i,1,n) scanf("%d",&num[i]); repf(i,1,n) { sum[i][i] = 0; repf(j,i+1,n) { sum[i][j] = sum[i][j-1]; if(num[i] > num[j]) sum[i][j]++; } } repd(j,n,1) { sum1[j][j] = 0; repd(i,j-1,1) { sum1[i][j] = sum1[i+1][j]; if(num[i] < num[j]) sum1[i][j]++; } } int cnt = 0; repf(i,1,n) repf(j,i+1,n) { if(num[i] > num[j]) cnt++; } //cout<<cnt<<endl; int ans1 = cnt; int ans2 = 0; //swap num[i] and num[j] repf(i,1,n) repf(j,i+1,n) { int temp = cnt - sum[i][j-1] + sum1[i+1][j] + (j - 1 - i - sum[i][j-1]) - (j - 1 - i - sum1[i+1][j]); //int temp = cnt + (j-i) - 2*sum[i][j-1] + 2*sum1[i+1][j] - (j-i); if(num[i] < num[j]) temp++; else temp--; ans1 = min(ans1,temp); } repf(i,1,n) repf(j,i+1,n) { int temp = cnt + (j-i) - 2*sum[i][j-1] + 2*sum1[i+1][j] - (j-i); if(num[i] < num[j]) temp++; else temp--; if(temp == ans1) ans2++; } cout<<ans1<<" "<<ans2<<endl; } return 0; }