#include <bits/stdc++.h>
using namespace std;
#define TR(i,v) 		for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x) 		cout << #x << " = "; cout << x << endl;
#define SIZE(p) 		(int)(p).size()
#define MP(a, b)		make_pair((a), (b))
#define ALL(p)			(p).begin(), (p).end()
#define rep(i, n)		for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)	for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)   	for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)  	for(int (i)=(int)(b); (i)>=(int)(a); --(i))
typedef long long LL;
typedef pair<int, int> pii;
const int maxn = 5005;
int p[maxn], Right[maxn], Left[maxn], b1[maxn], b2[maxn], c1[maxn], c2[maxn];
bool g1[maxn], g2[maxn];
bool cmp1(int i, int j){
	return Right[i] > Right[j];
}
bool cmp2(int i, int j){
	return Left[i] > Left[j];
}
int main(int argc, char const *argv[])
{
	#ifndef ONLINE_JUDGE
    freopen("C.in", "r", stdin);
    // freopen("out", "w", stdout);
    #endif
	// ios::sync_with_stdio(false);    cin.tie(0);
	int n;			scanf("%d", &n);
	rep(i, n)
		scanf("%d", p+i);
	rep(i, n)
	{
		REP(j, i+1, n)
			Right[i] += p[j]<p[i];
		rep(j, i)
			Left[i] += p[j]>p[i];
	}
	rep(i, n)
		b1[i] = b2[i] = i;
	sort(b1, b1+n, cmp1);
	sort(b2, b2+n, cmp2);
	// rep(i, n)
	// 	printf("%d ", Right[b1[i]]);		puts("");
	// rep(i, n)
	// 	printf("%d ", Left[b2[i]]);			puts("");
	int r = 0;
	int k = 0;
	for(int i=0; i<n && Right[b1[i]] == Right[b1[0]]; ++i)
		c1[k++] = b1[i], g1[b1[i]] = true;
	const int len1 = k;
	k = 0;
	for(int i=0; i<n && Left[b2[i]] == Left[b2[0]]; ++i)
		c2[k++] = b2[i], g2[b2[i]] = true;
	const int len2 = k;
	r = len1*len2;
	rep(i, len1)
		r -= g2[b1[i]];
	int p1=-1, p2=-1;
	rep(i, len1)	rep(j, len2)	if(c1[i] != c2[j])
	{
		p1 = c1[i], p2 = c2[j];		goto out;
	}
	out:
	// DEBUG(p1);
	// DEBUG(p2);
	int res = 0;
	if(~p1)
	{
		swap(p[p1], p[p2]);
		memset(Right, 0, sizeof(Right));
		memset(Left, 0, sizeof(Left));
		rep(i, n)
		{
			REP(j, i+1, n)
				Right[i] += p[j]<p[i];
			rep(j, i)
				Left[i] += p[j]>p[i];
		}
		rep(i, n)
			res += Right[i]+Left[i];
		res /= 2;
	}else
	{
		rep(i, n)
			res += Right[i]+Left[i];
		res /= 2;
	}
	printf("%d %d\n", res, r);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define TR(i,v) 		for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x) 		cout << #x << " = "; cout << x << endl;
#define SIZE(p) 		(int)(p).size()
#define MP(a, b)		make_pair((a), (b))
#define ALL(p)			(p).begin(), (p).end()
#define rep(i, n)		for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)	for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)   	for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)  	for(int (i)=(int)(b); (i)>=(int)(a); --(i))
typedef long long LL;
typedef pair<int, int> pii;
const int maxn = 5005;
int p[5005], tr[5005], n;
inline int getsum(int x)
{
	int r = 0;
	while(x)
	{
		r += tr[x];		x-=x&-x;
	}
	return r;
}
struct SegTree
{
    struct node
    {
        int l, r;
        vector<int> dic;
    } v[maxn<<2];
    inline int ll(int x)
    {
        return x<<1;
    }
    inline int rr(int x)
    {
        return x<<1|1;
    }
    inline int mm(int x)
    {
        return (v[x].l+v[x].r)>>1;
    }
    inline void pushup(int x)
    {
        v[x].dic.resize(SIZE(v[ll(x)].dic) + SIZE(v[rr(x)].dic));
        merge(ALL(v[ll(x)].dic), ALL(v[rr(x)].dic), v[x].dic.begin());
    }
    void build(int l, int r, int x=1)
    {
        v[x].l = l, v[x].r = r;
        if (v[x].l+1 == v[x].r)
        {
            v[x].dic.push_back(p[l]);
            return;
        }
        int m = mm(x);
        build(l, m, ll(x));
        build(m, r, rr(x));
        pushup(x);
    }
    int querybig(int l, int r, int x=1, int y=0)
    {
        if (l>=r)        return 0;
        if (l<=v[x].l && v[x].r<=r)
        {
    		int r = (int)(v[x].dic.end() - upper_bound(ALL(v[x].dic), y));
            return r;
        }
        int m = mm(x);
        if (m == v[x].l)            return 0;
        int res = 0;
        if (l < m)       res += querybig(l, r, ll(x), y);
        if (m < r)       res += querybig(l, r, rr(x), y);
        return res;
    }
    int querysml(int l, int r, int x=1, int y=0)
    {
        if (l>=r)        return 0;
        if (l<=v[x].l && v[x].r<=r)
        {
    		int r = (int)(lower_bound(ALL(v[x].dic), y) - v[x].dic.begin());
            return r;
        }
        int m = mm(x);
        if (m == v[x].l)            return 0;
        int res = 0;
        if (l < m)       res += querysml(l, r, ll(x), y);
        if (m < r)       res += querysml(l, r, rr(x), y);
        return res;
    }
}tt;
int ans[5005][5005];

int main(int argc, char const *argv[])
{
	#ifndef ONLINE_JUDGE
    freopen("C.in", "r", stdin);
    // freopen("out", "w", stdout);
    #endif
	// ios::sync_with_stdio(false);    cin.tie(0);
	scanf("%d", &n);
	FOR(i, 1, n)
		scanf("%d", p+i), ++p[i];
    // int n = 500;
    // FOR(i, 1, n)
    	// p[i] = i;			random_shuffle(p+1, p+1+n);
	int r1 = 0;
	FOR(i, 1, n)
	{
		int t = getsum(n) - getsum(p[i]);
		r1 += t;
		// DEBUG(p[i]);
		// DEBUG(getsum(p[i]));
		// DEBUG(t);
		for(int k=p[i]; k<=n; k+=k&-k)
			tr[k] += 1;
	}
	tt.build(1, n+1, 1);
	int r2 = r1;
	int r = (int)1e9;
	FOR(i, 1, n)
	{
		FOR(j, i+1, n)
		{
			r2 = r1;
			r2 -= tt.querysml(i+1, j+1, 1, p[i]);
			r2 += tt.querybig(i+1, j+1, 1, p[i]);
			r2 -= tt.querybig(i, j, 1, p[j]);
			r2 += tt.querysml(i, j, 1, p[j]);
			r2 += p[i] > p[j];
			if(i==1 && j==4)
			{
				// DEBUG(tt.querysml(i+1, j+1, 1, p[i]));
				// DEBUG(tt.querybig(i+1, j+1, 1, p[i]));
				// DEBUG(tt.querybig(i, j, 1, p[j]));
				// DEBUG(tt.querysml(i, j, 1, p[j]));
			}
			ans[i][j] = r2;
			r = min(r, ans[i][j]);
		}
	}
	// FOR(i, 1, n)
	// FOR(j, i+1, n)
	// 	printf("%d %d %d\n", i, j, ans[i][j]);
	int rc = 0;
	FOR(i, 1, n)
	FOR(j, i+1, n)		if(ans[i][j] == r)
		++rc;
	printf("%d %d\n", r, rc);
	return 0;
}


#include <limits.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <limits>
#include <cassert>
#include <string>
#include <vector>
#include <deque>
#include <fstream>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <queue>
#include <iterator>
#include <set>
static const int INF = std::numeric_limits<int>::max();
int sort(std::vector<int> v)
{
  int rv = 0;
  for(size_t i = 1; i < v.size(); ++i) {
    int j = i;
    while(j > 0 && v[j] < v[j - 1]) {
      ++rv;
      std::swap(v[j], v[j - 1]);
      --j;
    }
  }
  return rv;
}
int dcost(int i, int j, int v)
{
  return std::max(0, v - i) - std::max(0, v - j);
}
int cnt[5001][5001];
int main()
{
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for(int i = 0; i < n; ++i) {
    std::cin >> v[i];
  }
  for(int i = 0; i < n; ++i) {
    for(int j = 1; j <= n; ++j) {
      cnt[i][j] = cnt[i][j - 1];
      if(v[j - 1] > i) {
        ++cnt[i][j];
      }
    }
  }
  // for(int i = 0; i < n; ++i) {
  //   for(int j = 0; j <= n; ++j) {
  //     std::cout << cnt[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }

  int best = 0;
  auto res = std::vector<std::pair<int, int>>();
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      if(i == j) continue;
      int d = cnt[v[i]][i] - cnt[v[i]][j] + cnt[v[j]][j] - cnt[v[j]][i];
      //std::cout << i << "," << j << ", d=" << d << std::endl;
      if(best < d) {
        best = d;
        res.clear();
        res.emplace_back(i, j);
      } else if(best == d) {
        res.emplace_back(i, j);
      }
    }
  }
  // std::cout << best << std::endl;
  std::swap(v[res[0].first], v[res[0].second]);
  std::cout << sort(v) << " " << res.size() << std::endl;
  // for(auto& a: res) {
  //   std::cout << "(" << a.first << "," << a.second << "), ";
  // }
  // std::cout << std::endl;
}


#include <limits.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <limits>
#include <cassert>
#include <string>
#include <vector>
#include <deque>
#include <fstream>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <queue>
#include <iterator>
#include <set>
static const int INF = std::numeric_limits<int>::max();
int sort(std::vector<int> v)
{
  int rv = 0;
  for(size_t i = 1; i < v.size(); ++i) {
    int j = i;
    while(j > 0 && v[j] < v[j - 1]) {
      ++rv;
      std::swap(v[j], v[j - 1]);
      --j;
    }
  }
  return rv;
}

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for(int i = 0; i < n; ++i) {
    std::cin >> v[i];
  }
  int best = 0;
  auto res = std::vector<std::pair<int, int>>();
  for(int i = 0; i < n; ++i) {
    for(int j = i + 1; j < n; ++j) {
      if(i == j) continue;
      int d1 = abs(i - v[i]) - abs(j - v[i]);
      int d2 = abs(j - v[j]) - abs(i - v[j]);
      int d = d1 + d2;
      if(best < d) {
        best = d;
        res.clear();
        res.emplace_back(i, j);
      } else if(best == d) {
        res.emplace_back(i, j);
      }
    }
  }
  std::swap(v[res[0].first], v[res[0].second]);
  std::cout << sort(v) << " " << res.size() << std::endl;
  // for(auto& a: res) {
  //   std::cout << "(" << a.first << "," << a.second << "), ";
  // }
  // std::cout << std::endl;
}


#include<cstdio>
#include<iostream>

using namespace std;
#define M 5000 + 10
int mx[M][M] ,data[M], mi[M][M];

int main()
{
   // freopen("/home/administrator/桌面/001/input.txt","r",stdin);

    int n, sum;
    while(scanf("%d",&n) != EOF)
    {

        for(int i = 1 ; i <= n; ++ i)    scanf("%d",&data[i]);
        sum = 0;
        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {
                mx[i][j] = cur;
                if(data[j] > data[i]) ++ cur;
            }
            sum += mx[i][i];
        }
        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {
                if(data[j] < data[i]) ++ cur;
                mi[i][j] = cur;
            }
        }
        int ans  = sum;
        int num = 0;
        for(int i = 1 ; i <= n; ++ i)
        {
            for(int j = i + 1 ; j <= n; ++ j)
            {
                int tem = sum + mx[j][i] - mx[j][j] + mx[i][j] - mx[i][i] +(  mi[j][j] - mi[j][i - 1] ) - (mi[i][j] - mi[i][i - 1]) ;
                if(tem < ans)
                {
                    ans = tem;
                    num = 1;
                }
                else if(tem == ans) ++ num;
            }
        }
        printf("%d %d\n",ans + 1,num);
    }
    return 0;
}


#include<cstdio>
#include<iostream>

using namespace std;
#define M 5000 + 10
int mx[M][M] ,data[M], mi[M][M];

int main()
{
    freopen("/home/administrator/桌面/001/input.txt","r",stdin);
    int n, sum;
    while(scanf("%d",&n) != EOF)
    {

        for(int i = 1 ; i <= n; ++ i)    scanf("%d",&data[i]);
        sum = 0;
        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {

                if(data[j] > data[i]) ++ cur;
                mx[i][j] = cur;
            }
            sum += mx[i][i];
        }

        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {
                if(data[j] < data[i]) ++ cur;
                mi[i][j] = cur;
            }
        }

        int ans  = sum;
        int num = 0;
        for(int i = 1 ; i < n; ++ i)
        {
            for(int j = i + 1 ; j <= n; ++ j)
            {
                int tem = sum + mx[j][i] - mx[j][j] + mx[i][j] - mx[i][i] + (mi[j][j] - mi[j][i -1]) - (mi[i][j] - mi[i][i - 1]) ;
                if(tem < ans)
                {
                    ans = tem;
                    num = 1;
                }
                else if(tem == ans) ++ num;
            }
        }
        printf("%d %d\n",ans ,num);
    }
    return 0;
}


#include<cstdio>
#include<iostream>

using namespace std;
#define M 5000 + 10
int mx[M][M] ,data[M], mi[M][M];

int main()
{
    freopen("/home/administrator/桌面/001/input.txt","r",stdin);

    int n, sum;
    while(scanf("%d",&n) != EOF)
    {

        for(int i = 1 ; i <= n; ++ i)    scanf("%d",&data[i]);
        sum = 0;
        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {
                mx[i][j] = cur;
                if(data[j] > data[i]) ++ cur;
            }
            sum += mx[i][i];
        }
        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {
                if(data[j] < data[i]) ++ cur;
                mi[i][j] = cur;
            }
        }
        int ans  = sum;
        int num = 0;
        for(int i = 1 ; i <= n; ++ i)
        {
            for(int j = i + 1 ; j <= n; ++ j)
            {
                int tem = sum + mx[j][i] - mx[j][j] + mx[i][j] - mx[i][i] +(  mi[j][j] - mi[j][i - 1] ) - (mi[i][j] - mi[i][i - 1]) ;
                if(tem < ans)
                {
                    ans = tem;
                    num = 1;
                }
                else if(tem == ans) ++ num;
            }
        }
        printf("%d %d\n",ans + 1,num);
    }
    return 0;
}


#include<cstdio>
#include<iostream>

using namespace std;
#define M 5000 + 10
int mx[M][M] ,data[M], mi[M][M];

int main()
{
    //freopen("/home/administrator/桌面/001/input.txt","r",stdin);
    int n, sum;
    while(scanf("%d",&n) != EOF)
    {

        for(int i = 1 ; i <= n; ++ i)    scanf("%d",&data[i]);
        sum = 0;
        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {

                if(data[j] > data[i]) ++ cur;
                mx[i][j] = cur;
            }
            sum += mx[i][i];
        }

        for(int i = 1 ; i <= n; ++ i)
        {
            int cur = 0;
            for(int j = 1 ; j <= n; ++ j)
            {
                if(data[j] < data[i]) ++ cur;
                mi[i][j] = cur;
            }
        }

        int ans  = sum;
        int num = 0;
        for(int i = 1 ; i < n; ++ i)
        {
            for(int j = i + 1 ; j <= n; ++ j)
            {
                int tem = sum + mx[j][i] - mx[j][j] + mx[i][j] - mx[i][i] + (mi[j][j] - mi[j][i -1]) - (mi[i][j] - mi[i][i - 1]) ;
                if(tem < ans)
                {
                    ans = tem;
                    num = 1;
                }
                else if(tem == ans) ++ num;
            }
        }
        printf("%d %d\n",ans ,num);
    }
    return 0;
}


#include <bits/stdc++.h>
#ifdef LOCAL
#include "local.h"
#endif

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define clr(a, x) memset(a, x, sizeof(a))
#define sz(a) ((int)(a).size())
#define mp(a, b) make_pair(a, b)

template <typename T, typename U> void upmin(T& a, const U& b) { a = min<T>(a, b); }
template <typename T, typename U> void upmax(T& a, const U& b) { a = max<T>(a, b); }
template <typename T> void uniq(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

void fast_io() { cin.tie(0); ios::sync_with_stdio(false); }
bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

typedef long long ll;
typedef pair<int, int> pint;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

int main()
{
    int n, a[5555];
    cin >> n;
    rep(i, n)
        cin >> a[i];

    static int sum[5555][5555];
    rep(i, n) for (int j = i; j < n; j++)
        sum[j + 1][a[i]]++;
    rep(i, n) rep(j, n)
        sum[i + 1][j + 1] += sum[i + 1][j];

    int max_reduce = -11111;
    int num = 0;
    rep(j, n) rep(i, j)
    {
        int reduce = 2 * ((sum[j][a[i]] - sum[i + 1][a[i]]) - (sum[j][a[j]] - sum[i + 1][a[j]])) + (a[i] < a[j] ? -1 : 1);
        if (reduce > max_reduce)
        {
            max_reduce = reduce;
            num = 0;
        }
        if (reduce == max_reduce)
            num++;
    }

    int rev = 0;
    rep(j, n) rep(i, j)
        if (a[i] > a[j])
            rev++;
    cout << rev - max_reduce << " " << num << endl;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pp;
#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define FOR(i, n) for(int i = 0; i < int(n); i++)
#define FORAB(i, a, b) for(int i = int(a); i <= int(b); i++)
#define FORBA(i, b, a) for(int i = int(b); i >= int(a); i--)
#define FORTR(it, container) for(auto it = container.begin(); it != container.end(); it++)
#define FORTRR(it, container) for(auto it = container.end(); it != container.begin(); it++)
#define popcount(x) __builtin_popcount(x)
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) ((x)*(y))/gcd(x,y)
#define sqr(x) ((x)*(x))
#define debug(x) cerr<< #x <<" = "<<x<<endl;
template<typename T1, typename T2> std::ostream& operator<<(std::ostream& out,const std::pair<T1, T2> &M) {
 out<<"<"; out<<M.first<<","<<M.second;out<<">";return out;}
template<typename T1, typename T2> std::ostream& operator<< (std::ostream& out,const std::map<T1,T2> &M) {
 out<<"{ ";for(auto item:M)out<<item.first<<" : "<<item.second<<", ";out<<"}";return out; }
template<typename T1> std::ostream& operator<<(std::ostream& out,const std::vector<T1> &M) {
 out<<"< ";for(auto tr:M)out<<tr<<", ";out<<">";return out;}
template<typename T1> std::ostream& operator<<(std::ostream& out,const std::set<T1> &M) {
 out << "{ ";for (auto tr:M)out<<tr<<", ";out<<"}";return out;}
template<typename T1> std::ostream& operator<<(std::ostream& out,const std::multiset<T1> &M) {
 out << "{ ";for (auto tr:M)out<<tr<<", ";out<<"}";return out;}
#define inp(x) cin>>x
#define out(x) cout<<x
const int inf = 1e9;
const long long MAXINT_64 = numeric_limits<ll>::max();
const long long MININT_64 = numeric_limits<ll>::min();
const long double PI = ld(3.1415926535897932384626433832795);

int arr[5001];
int mem[5001][5001][2] = {0};
int main(){
    ios::sync_with_stdio(false);
    int n; inp(n);
    FOR(i,n){
    	inp(arr[i]);
    }
    int ninv = 0;
    for(int i=0;i<n;i++){
    	for(int j=i+1;j<n;j++){
    		if(arr[j] < arr[i])
    			ninv++;
    	}
    }
//    debug(ninv);
    for(int i=0;i<n;i++){
    	for(int num=0;num<n;num++){
    		if(i == 0){
    			if(arr[i] < num){
    				mem[i][num][0]++;
    			}
    			if(arr[i] > num){
    				mem[i][num][1]++;
    			}
    		} else {
    			mem[i][num][0] = mem[i-1][num][0];
    			mem[i][num][1] = mem[i-1][num][1];
    			if(arr[i] < num){
    				mem[i][num][0] += 1;
    			}
    			if(arr[i] > num){
    				mem[i][num][1] += 1;
    			}
    		}
    	}
    }
    int mininv = ninv;
    int cnt = 0;
    for(int i=0;i<n;i++){
    	for(int j=0;j<i;j++){
    		int newinv = ninv;
    		if(arr[j] < arr[i])
    			newinv++;
    		else
    			newinv--;
    		if(i-j > 1){
    			int t1 = mem[i-1][arr[i]][1] - mem[j][arr[i]][1];
    			int t2 = mem[i-1][arr[i]][0] - mem[j][arr[i]][0];
    			int t3 = mem[i-1][arr[j]][1] - mem[j][arr[j]][1];
    			int t4 = mem[i-1][arr[j]][0] - mem[j][arr[j]][0];
    			newinv += -t1+t2+t3-t4;
    		}
    		if(newinv < mininv){
    			mininv = newinv;
    			cnt = 1;
    		} else if(newinv == mininv){
    			cnt++;
    		}
    	}
    }
    cout<<mininv<<" "<<cnt;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#define CLR(x,y) memset(x,y,sizeof(x))
#define eps 1e-9
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

template<class T>
inline bool read(T &n)
{
    T x = 0, tmp = 1; char c = getchar();
    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
    if(c == EOF) return false;
    if(c == '-') c = getchar(), tmp = -1;
    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
    n = x*tmp;
    return true;
}
template <class T>
inline void write(T n)
{
    if(n < 0)
    {
        putchar('-');
        n = -n;
    }
    int len = 0,data[20];
    while(n)
    {
        data[len++] = n%10;
        n /= 10;
    }
    if(!len) data[len++] = 0;
    while(len--) putchar(data[len]+48);
}
//-----------------------------------

//我们枚举pair(A[i], A[j])，且i < j。
//此时对于逆序数的变化值为 (A[i+1 ... j-1]中小于j的数的个数) + (A[i+1 ... j-1]中大于i的个数)

const int MAXN=5555;
int a[MAXN];
int po[MAXN];
int dp[MAXN][MAXN];

int main()
{
    int n,i,j;
    read(n);
    for(i=0; i<n; i++)
    {
        read(a[i]);
        po[a[i]]=i;
    }
    for(i=0; i<n; i++)
        for(j=n-1;j>=0;j--)
        {
            if(a[j]<i)
				dp[i][j]++;
            dp[i][j]+=dp[i][j+1];
        }
    int sum=0;
    for(i=0;i<n;i++)
        sum+=dp[i][po[i]];
    int minn=sum,num=0;
    for(i=0; i<n; i++)
    {
        for(j=0; j<i; j++)
        {
            if(a[i]>a[j])
				continue;
            int aa=dp[a[i]][j]-dp[a[i]][i];
            int bb=dp[a[j]][j]-dp[a[j]][i];
            int change=sum+2*aa-(2*bb+1);
            if(change<minn)
                minn=change,num=1;
            else if(change==minn)
                num++;
        }
    }
    write(minn);putchar(' ');write(num);putchar('\n');
    return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int a[5555];
int dp[5555][5555] = { 0 };

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++) {
		for(int j = i - 1; j >= 0; j--)
			dp[i][j] = dp[i][j + 1] + (a[j] > a[i]);
		for(int j = i + 1; j < n; j++)
			dp[i][j] = dp[i][j - 1] + (a[j] > a[i]);
	}
	int x = 0, ans = 0, res = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < i; j++)
			ans += (a[j] > a[i]);
	}
	x = ans;
	for(int i = 0; i < n; i++)
		for(int j = i + 1; j < n; j++) {
			int tmp = x - 2 * dp[j][i + 1] + 2 * dp[i][j - 1];
			if(a[i] > a[j]) tmp--;
			else tmp++;
			if(ans == tmp) res++;
			else if(tmp < ans) ans = tmp, res = 1;
		}
	cout << ans << " " << res << endl;
}


/*
 Author:   Harhro94 [Harutyunyan Hrayr]
 IDE:      Visual C++ 2012
*/
//#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <string>
#include <bitset>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

const int N = 5007;
int n, a[N], above[N][N], below[N][N];

int main()
{
#ifdef harhro94
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
    //freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#endif

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int inv = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j)
            if (a[i] > a[j]) ++inv;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            above[i][j] = above[i - 1][j] + (a[i] > j ? 1 : 0);
            below[i][j] = below[i - 1][j] + (a[i] < j ? 1 : 0);
        }
    }
    int best = N * N;
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            int diff = (above[j][a[i]] - above[i - 1][a[i]]) + (below[j][a[j]] - below[i - 1][a[j]])
                       - (below[j][a[i]] - below[i - 1][a[i]]) - (above[j][a[j]] - above[i - 1][a[j]]);
            if (a[i] <= a[j]) --diff;
            else ++diff;
            int newInv = inv + diff;
            if (newInv < best)
            {
                best = newInv;
                cnt = 0;
            }
            if (newInv == best) ++cnt;
        }
    }
    cout << best << " " << cnt << endl;

#ifdef harhro94
    cerr << fixed << setprecision(3) << "\nExecution time = " << clock() / 1000.0 << "s\n";
#endif
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int Sort(vector<int> &a) {
    int count = 0;
    int n = a.size();
    for (int i = 1; i< n; ++i) {
        int j = i;
        while (j > 0 && a[j] < a[j-1]) {
            swap(a[j], a[j-1]);
            ++count;
            --j;
        }
    }
    return count;
}
int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    vector<vector<int> > a(n);
    for (int i = 0; i < n; ++i) {
        a[i].resize(n);
        int count = 0;
        for (int j = 0; j < n; ++j) {
            if (v[j] >= v[i])
                count++;
            a[i][j] = count;
//            cout << a[i][j] << ' ';
        }
//        cout << endl;
    }
//    cout << endl;
    int minimal = 0;
    int count = 0;
    int I = 0;
    int J = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int delta = -(a[i][i] + a[j][j] - a[i][j] - a[j][i]);
            if (delta < minimal) {
                minimal = delta;
                count = 0;
                I = i;
                J = j;
            }
            if (delta == minimal)
                ++count;
        }
    }
    swap(v[I], v[J]);
    cout << Sort(v) << ' ' << count << endl;

}


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 1e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i =0; i < N; i++) cin >> P[i];

    int S =0;
    for(int i =0; i < N; i++) S +=abs(i-P[i]);

    int ansA =S;
    for(int i =0; i < N; i++) for(int j =i+1; j < N; j++)
        ansA =min(ansA,S-abs(i-P[i])-abs(j-P[j])+abs(i-P[j])+abs(j-P[i]));

    int ansB =0;
    for(int i =0; i < N; i++) for(int j =i+1; j < N; j++)
        if(ansA == S-abs(i-P[i])-abs(j-P[j])+abs(i-P[j])+abs(j-P[i])) ansB++;

    cout << ansA/2 << " " << ansB << "\n";
    return 0;}

// look at my code
// my code is amazing


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 1e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;4 0 3 1 2

int main() {
    cin.sync_with_stdio(0);
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i =0; i < N; i++) cin >> P[i];

    int S =0;
    for(int i =0; i < N; i++) S +=abs(i-P[i]);

    int ansA =S;
    for(int i =0; i < N; i++) for(int j =i+1; j < N; j++)
        ansA =min(ansA,S-abs(i-P[i])-abs(j-P[j])+abs(i-P[j])+abs(j-P[i]));

    int ansB =0;
    for(int i =0; i < N; i++) for(int j =i+1; j < N; j++)
        if(ansA == S-abs(i-P[i])-abs(j-P[j])+abs(i-P[j])+abs(j-P[i])) ansB++;

    cout << ansA/2 << " " << ansB << "\n";
    return 0;}

// look at my code
// my code is amazing


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 1e-7
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
// mylittlepony
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i =0; i < N; i++) cin >> P[i];

    vector< vector<int> > costG(N, vector<int>(N));
    for(int i =0; i < N; i++) {
        int x =0;
        for(int j =i+1; j < N; j++) {
            costG[i][j] =x;
            if(P[j] > P[i]) x++;}
        x =0;
        for(int j =i-1; j >= 0; j--) {
            costG[i][j] =x;
            if(P[j] > P[i]) x++;}}

    vector< vector<int> > costL(N, vector<int>(N));
    for(int i =N-1; i >= 0; i--) {
        int x =0;
        for(int j =i-1; j >= 0; j--) {
            costL[i][j] =x;
            if(P[j] < P[i]) x++;}
        x =0;
        for(int j =i+1; j < N; j++) {
            costL[i][j] =x;
            if(P[j] < P[i]) x++;}}

    int S =0;
    for(int i =0; i < N; i++) for(int j =i+1; j < N; j++)
        if(P[i] > P[j]) S++;

    int ansA =S, ansB =0;
    for(int i =0; i < N; i++) for(int j =i+1; j < N; j++)
        ansA =min(ansA,S-2*(int)(P[i] > P[j])+1-costL[i][j]-costG[j][i]+costL[j][i]+costG[i][j]);

    for(int i =0; i < N; i++) for(int j =i+1; j < N; j++)
        if(ansA == S-2*(int)(P[i] > P[j])+1-costL[i][j]-costG[j][i]+costL[j][i]+costG[i][j]) ansB++;

    cout << ansA << " " << ansB << "\n";
    return 0;}

// look at my code
// my code is amazing


#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

typedef unsigned int u32;
inline int popcount(u32 x) {
    x = x - ((x >> 1) & 0x55555555);
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
    return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
struct SimpleFID {
    int length, count, tablesize; vector<u32> blocks; vector<int> ranks;
    SimpleFID(int len): length(len) {
        tablesize = (len + 31) / 32;
        blocks.resize(tablesize + 1); ranks.resize(tablesize + 1);
    }
    void set(int pos) { blocks[pos / 32] |= 1 << pos % 32; }
    void build() {
        count = 0;
        for(int i = 0; i < tablesize; i ++)
            ranks[i] = count, count += popcount(blocks[i]);
    }
    int rank(int pos) const {
        return ranks[pos / 32] + popcount(blocks[pos / 32] & (1 << pos % 32)-1);
    }
    int rank(bool b, int pos) const { return b ? rank(pos) : pos - rank(pos); }
};
struct SimpleWaveletMatrix {
    typedef unsigned long long u64;
    int length, bitsize; u64 maxval;
    vector<SimpleFID> dicts; vector<int> mids;
    void init(const vector<u64>& data) {
        length = data.size();
        maxval = *max_element(data.begin(), data.end());
        if(1ULL << (8 * sizeof(u64) - 1) <= maxval) bitsize = 8 * sizeof(u64);
        else for(bitsize = 0; u64(1) << bitsize <= maxval; bitsize ++) ;
        dicts.assign(bitsize, length);
        mids.assign(bitsize, 0);
        vector<u64> datacurrent(data), datanext(length);
        for(int bit = 0; bit < bitsize; bit ++) {
            int pos = 0;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) == 0)
                    datanext[pos ++] = datacurrent[i];
            mids[bit] = pos;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) != 0)
                    dicts[bit].set(i), datanext[pos ++] = datacurrent[i];
            dicts[bit].build();
            datacurrent.swap(datanext);
        }
    }
    int rank_all(u64 val, int left, int right, int& out_lt, int& out_gt) const {
        if(val > maxval) { out_lt = right - left; out_gt = 0; return 0; }
        out_lt = out_gt = 0;
        for(int bit = 0; bit < bitsize; bit ++) {
            bool dir = val >> (bitsize - bit - 1) & 1;
            int leftcount = dicts[bit].rank(dir, left), rightcount = dicts[bit].rank(dir, right);
            (dir ? out_lt : out_gt) += rightcount - leftcount;
            left = leftcount, right = rightcount;
            if(dir) left += mids[bit], right += mids[bit];
        }
        return right - left;
    }

    inline int rank_lt(u64 val, int left, int right) const {
        int tmp_lt, tmp_gt;
        rank_all(val, left, right, tmp_lt, tmp_gt);
        return tmp_lt;
    }
    inline int rangefreq(int left, int right, u64 bottom, u64 up) {
        return rank_lt(up, left, right) - rank_lt(bottom, left, right);
    }
};

int simu(vi a) {
    int n = a.size();
    int r = 0;
    for(int i = 1; i < n; i ++) {
        int j = i;
        while(j > 0 && a[j] < a[j-1]) {
            r ++;
            swap(a[j], a[j-1]);
            j = j - 1;
        }
    }
    return r;
}

int a[5000], cost[5000];
vi sorted[5000];
int getcost(int i, int x) {
    return i - (upper_bound(all(sorted[i]), x) - sorted[i].begin());
}
int main() {
    int n, xm = -1, ym = -1, mi = INF;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        vi v = vi(a, a+i);
        sort(all(v));
        sorted[i] = v;
    }
    vector<unsigned long long> data;
    rep(i, n) data.pb(a[i]);
    SimpleWaveletMatrix w;
    w.init(data);

    rep(x, n) reu(y, x+1, n) {
        int t = 0;
        t -= getcost(x, a[x]);
        t += getcost(x, a[y]);
        t -= getcost(y, a[y]);
        t += getcost(y, a[x]);

        if(a[y] < a[x]) t -= w.rangefreq(x+1, y, a[y]+1, a[x]-1);
        if(a[x] < a[y]) t += w.rangefreq(x+1, y, a[x]+1, a[y]-1);
        if(t < mi) {
            xm = x;
            ym = y;
            mi = t;
        }
    }
    cout << xm << " " << ym << endl;
    cerr << mi << endl;

//  cerr << "before: "<< simu(vi(a,a+n)) << endl;
    swap(a[xm], a[ym]);
//  cerr << "after: " << simu(vi(a,a+n)) << endl;
    return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

/*
int simu(vi a) {
    int n = a.size();
    int r = 0;
    for(int i = 1; i < n; i ++) {
        int j = i;
        while(j > 0 && a[j] < a[j-1]) {
            r ++;
            swap(a[j], a[j-1]);
            j = j - 1;
        }
    }
    return r;
}
*/

int a[5000], cost[5000];
vi sorted[5000];
int getcost(int i, int x) {
    return i - (upper_bound(all(sorted[i]), x) - sorted[i].begin());
}
int main() {
    int n, xm = -1, ym = -1, mi = INF;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        vi v = vi(a, a+i);
        sort(all(v));
        sorted[i] = v;
    }

    rep(x, n) reu(y, x+1, n) {
        int t = 0;
        t -= getcost(x, a[x]);
        t += getcost(x, a[y]);
        t -= getcost(y, a[y]);
        t += getcost(y, a[x]);
        if(t < mi) {
            xm = x;
            ym = y;
            mi = t;
        }
    }
    cout << xm << " " << ym << endl;

//  cerr << "before: "<< simu(vi(a,a+n)) << endl;
//  swap(a[xm], a[ym]);
//  cerr << "after: " << simu(vi(a,a+n)) << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

typedef unsigned int u32;
inline int popcount(u32 x) {
    x = x - ((x >> 1) & 0x55555555);
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
    return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
struct SimpleFID {
    int length, count, tablesize; vector<u32> blocks;
    vector<unsigned short> ranks;
    SimpleFID(int len): length(len) {
        tablesize = (len + 31) / 32;
        blocks.resize(tablesize + 1);
        ranks.resize(length + 1);
    }
    void set(int pos) { blocks[pos / 32] |= 1 << pos % 32; }
    void build() {
        count = 0;
        for(int i = 0; i < length; i ++) {
            ranks[i] = count;
            count += blocks[i / 32] >> i % 32 & 1;
        }
        ranks[length] = count;
    }
    inline int rank(int pos) const {
        return ranks[pos];
    }
    inline int rank(bool b, int pos) const { return b ? rank(pos) : pos - rank(pos); }
};
struct SimpleWaveletMatrix {
    typedef unsigned short Val;
    int length, bitsize; Val maxval;
    vector<SimpleFID> dicts; vector<int> mids;
    void init(const vector<Val>& data) {
        length = data.size();
        maxval = *max_element(data.begin(), data.end());
        if(1ULL << (8 * sizeof(Val) - 1) <= maxval) bitsize = 8 * sizeof(Val);
        else for(bitsize = 0; Val(1) << bitsize <= maxval; bitsize ++) ;
        dicts.assign(bitsize, length);
        mids.assign(bitsize, 0);
        vector<Val> datacurrent(data), datanext(length);
        for(int bit = 0; bit < bitsize; bit ++) {
            int pos = 0;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) == 0)
                    datanext[pos ++] = datacurrent[i];
            mids[bit] = pos;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) != 0)
                    dicts[bit].set(i), datanext[pos ++] = datacurrent[i];
            dicts[bit].build();
            datacurrent.swap(datanext);
        }
    }
    int rank_all(Val val, int left, int right, int& out_lt, int& out_gt) const {
        if(val > maxval) { out_lt = right - left; out_gt = 0; return 0; }
        out_lt = out_gt = 0;
        for(int bit = 0; bit < bitsize; bit ++) {
            bool dir = val >> (bitsize - bit - 1) & 1;
            int leftcount = dicts[bit].rank(dir, left), rightcount = dicts[bit].rank(dir, right);
            (dir ? out_lt : out_gt) += (right - left) - (rightcount - leftcount);
            left = leftcount, right = rightcount;
            if(dir) left += mids[bit], right += mids[bit];
        }
        return right - left;
    }
    inline int rank_lt(Val val, int left, int right) const {
        int tmp_lt, tmp_gt;
        rank_all(val, left, right, tmp_lt, tmp_gt);
        return tmp_lt;
    }
    inline int rangefreq(int left, int right, Val bottom, Val up) {
        return rank_lt(up, left, right) - rank_lt(bottom, left, right);
    }
};

int simu(vi a) {
    int n = a.size();
    int r = 0;
    for(int i = 1; i < n; i ++) {
        int j = i;
        while(j > 0 && a[j] < a[j-1]) {
            r ++;
            swap(a[j], a[j-1]);
            j = j - 1;
        }
    }
    return r;
}

int a[5000], cost[5000], costcosts[5000];
vi sorted[5000];
int getcost(int i, int x) {
    return i - (upper_bound(all(sorted[i]), x) - sorted[i].begin());
}
int main() {
    int n, xm = -1, ym = -1, mi = INF, micnt = 0;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        vi v = vi(a, a+i);
        sort(all(v));
        sorted[i] = v;
    }
    vector<unsigned short> data;
    rep(i, n) data.pb(a[i]);
    SimpleWaveletMatrix w;
    w.init(data);

    rep(x, n) costcosts[x] = getcost(x, a[x]);
    vi randperm(n);
    rep(i, n) randperm[i] = i;
    random_shuffle(all(randperm));
    rep(xi, n) {
        int x = randperm[xi];
        int yxcost = costcosts[x];
        reu(y, x+1, n) {
           int t = 0;
            t -= costcosts[x];
            t -= costcosts[y];
            t += yxcost; // getcost(y, a[x]);

            if(a[y] < a[x]) t -= w.rangefreq(x+1, y, a[y]+1, a[x]);
            if(t <= mi) t += getcost(x, a[y]);
            if(a[x] < a[y]) if(t <= mi) t += w.rangefreq(x+1, y, a[x]+1, a[y]);
            if(t < mi) {
                xm = x;
                ym = y;
                mi = t;
                micnt = 0;
            }
            if(t == mi) micnt ++;
            yxcost += a[x] < a[y];
        }
    }

    cerr << mi << endl;
    int before = simu(vi(a,a+n));
    cerr << "before: "<<before << endl;
    swap(a[xm], a[ym]);
    int after = simu(vi(a,a+n));
    cerr << "after: " << after << endl;
    assert(before + mi == after);

    cout << after << " " << micnt << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

/*
int simu(vi a) {
    int n = a.size();
    int r = 0;
    for(int i = 1; i < n; i ++) {
        int j = i;
        while(j > 0 && a[j] < a[j-1]) {
            r ++;
            swap(a[j], a[j-1]);
            j = j - 1;
        }
    }
    return r;
}
*/

int a[5000];
int main() {
    int n, x = -1, y = -1;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        if(a[i] > i) x = i;
        if(a[i] < i) y = i;
    }
    cout << x << " " << y << endl;
//  cerr << simu(vi(a,a+n)) << endl;
    swap(a[x], a[y]);
//  cerr << simu(vi(a,a+n)) << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

typedef unsigned int u32;
inline int popcount(u32 x) {
    x = x - ((x >> 1) & 0x55555555);
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
    return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
struct SimpleFID {
    int length, count, tablesize; vector<u32> blocks; vector<int> ranks;
    SimpleFID(int len): length(len) {
        tablesize = (len + 31) / 32;
        blocks.resize(tablesize + 1); ranks.resize(tablesize + 1);
    }
    void set(int pos) { blocks[pos / 32] |= 1 << pos % 32; }
    void build() {
        count = 0;
        for(int i = 0; i < tablesize; i ++)
            ranks[i] = count, count += popcount(blocks[i]);
    }
    int rank(int pos) const {
        return ranks[pos / 32] + popcount(blocks[pos / 32] & (1 << pos % 32)-1);
    }
    int rank(bool b, int pos) const { return b ? rank(pos) : pos - rank(pos); }
};
struct SimpleWaveletMatrix {
    typedef unsigned long long u64;
    int length, bitsize; u64 maxval;
    vector<SimpleFID> dicts; vector<int> mids;
    void init(const vector<u64>& data) {
        length = data.size();
        maxval = *max_element(data.begin(), data.end());
        if(1ULL << (8 * sizeof(u64) - 1) <= maxval) bitsize = 8 * sizeof(u64);
        else for(bitsize = 0; u64(1) << bitsize <= maxval; bitsize ++) ;
        dicts.assign(bitsize, length);
        mids.assign(bitsize, 0);
        vector<u64> datacurrent(data), datanext(length);
        for(int bit = 0; bit < bitsize; bit ++) {
            int pos = 0;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) == 0)
                    datanext[pos ++] = datacurrent[i];
            mids[bit] = pos;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) != 0)
                    dicts[bit].set(i), datanext[pos ++] = datacurrent[i];
            dicts[bit].build();
            datacurrent.swap(datanext);
        }
    }
    int rank_all(u64 val, int left, int right, int& out_lt, int& out_gt) const {
        if(val > maxval) { out_lt = right - left; out_gt = 0; return 0; }
        out_lt = out_gt = 0;
        for(int bit = 0; bit < bitsize; bit ++) {
            bool dir = val >> (bitsize - bit - 1) & 1;
            int leftcount = dicts[bit].rank(dir, left), rightcount = dicts[bit].rank(dir, right);
            (dir ? out_lt : out_gt) += (right - left) - (rightcount - leftcount);
            left = leftcount, right = rightcount;
            if(dir) left += mids[bit], right += mids[bit];
        }
        return right - left;
    }
    inline int rank_lt(u64 val, int left, int right) const {
        int tmp_lt, tmp_gt;
        rank_all(val, left, right, tmp_lt, tmp_gt);
        return tmp_lt;
    }
    inline int rangefreq(int left, int right, u64 bottom, u64 up) {
        return rank_lt(up, left, right) - rank_lt(bottom, left, right);
    }
};

int simu(vi a) {
    int n = a.size();
    int r = 0;
    for(int i = 1; i < n; i ++) {
        int j = i;
        while(j > 0 && a[j] < a[j-1]) {
            r ++;
            swap(a[j], a[j-1]);
            j = j - 1;
        }
    }
    return r;
}

int a[5000], cost[5000];
vi sorted[5000];
int getcost(int i, int x) {
    return i - (upper_bound(all(sorted[i]), x) - sorted[i].begin());
}
int main() {
    int n, xm = -1, ym = -1, mi = INF;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        vi v = vi(a, a+i);
        sort(all(v));
        sorted[i] = v;
    }
    vector<unsigned long long> data;
    rep(i, n) data.pb(a[i]);
    SimpleWaveletMatrix w;
    w.init(data);

    rep(x, n) reu(y, x+1, n) {
        int t = 0;
        t -= getcost(x, a[x]);
        t += getcost(x, a[y]);
        t -= getcost(y, a[y]);
        t += getcost(y, a[x]);

        if(a[y] < a[x]) t -= w.rangefreq(x+1, y, a[y]+1, a[x]);
        if(a[x] < a[y]) t += w.rangefreq(x+1, y, a[x]+1, a[y]);
        if(t < mi) {
            xm = x;
            ym = y;
            mi = t;
        }
    }
    cout << xm << " " << ym << endl;
    cerr << mi << endl;

//  cerr << "before: "<< simu(vi(a,a+n)) << endl;
//  swap(a[xm], a[ym]);
//  cerr << "after: " << simu(vi(a,a+n)) << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

typedef unsigned int u32;
inline int popcount(u32 x) {
    x = x - ((x >> 1) & 0x55555555);
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
    return ((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
struct SimpleFID {
    int length, count, tablesize; vector<u32> blocks; vector<int> ranks;
    SimpleFID(int len): length(len) {
        tablesize = (len + 31) / 32;
        blocks.resize(tablesize + 1); ranks.resize(tablesize + 1);
    }
    void set(int pos) { blocks[pos / 32] |= 1 << pos % 32; }
    void build() {
        count = 0;
        for(int i = 0; i < tablesize; i ++)
            ranks[i] = count, count += popcount(blocks[i]);
    }
    int rank(int pos) const {
        return ranks[pos / 32] + popcount(blocks[pos / 32] & (1 << pos % 32)-1);
    }
    int rank(bool b, int pos) const { return b ? rank(pos) : pos - rank(pos); }
};
struct SimpleWaveletMatrix {
    typedef unsigned long long u64;
    int length, bitsize; u64 maxval;
    vector<SimpleFID> dicts; vector<int> mids;
    void init(const vector<u64>& data) {
        length = data.size();
        maxval = *max_element(data.begin(), data.end());
        if(1ULL << (8 * sizeof(u64) - 1) <= maxval) bitsize = 8 * sizeof(u64);
        else for(bitsize = 0; u64(1) << bitsize <= maxval; bitsize ++) ;
        dicts.assign(bitsize, length);
        mids.assign(bitsize, 0);
        vector<u64> datacurrent(data), datanext(length);
        for(int bit = 0; bit < bitsize; bit ++) {
            int pos = 0;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) == 0)
                    datanext[pos ++] = datacurrent[i];
            mids[bit] = pos;
            for(int i = 0; i < length; i ++)
                if((datacurrent[i] >> (bitsize - bit - 1) & 1) != 0)
                    dicts[bit].set(i), datanext[pos ++] = datacurrent[i];
            dicts[bit].build();
            datacurrent.swap(datanext);
        }
    }
    int rank_all(u64 val, int left, int right, int& out_lt, int& out_gt) const {
        if(val > maxval) { out_lt = right - left; out_gt = 0; return 0; }
        out_lt = out_gt = 0;
        for(int bit = 0; bit < bitsize; bit ++) {
            bool dir = val >> (bitsize - bit - 1) & 1;
            int leftcount = dicts[bit].rank(dir, left), rightcount = dicts[bit].rank(dir, right);
            (dir ? out_lt : out_gt) += rightcount - leftcount;
            left = leftcount, right = rightcount;
            if(dir) left += mids[bit], right += mids[bit];
        }
        return right - left;
    }

    inline int rank_lt(u64 val, int left, int right) const {
        int tmp_lt, tmp_gt;
        rank_all(val, left, right, tmp_lt, tmp_gt);
        return tmp_lt;
    }
    inline int rangefreq(int left, int right, u64 bottom, u64 up) {
        return rank_lt(up, left, right) - rank_lt(bottom, left, right);
    }
};

int simu(vi a) {
    int n = a.size();
    int r = 0;
    for(int i = 1; i < n; i ++) {
        int j = i;
        while(j > 0 && a[j] < a[j-1]) {
            r ++;
            swap(a[j], a[j-1]);
            j = j - 1;
        }
    }
    return r;
}

int a[5000], cost[5000];
vi sorted[5000];
int getcost(int i, int x) {
    return i - (upper_bound(all(sorted[i]), x) - sorted[i].begin());
}
int main() {
    int n, xm = -1, ym = -1, mi = INF;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        vi v = vi(a, a+i);
        sort(all(v));
        sorted[i] = v;
    }
    vector<unsigned long long> data;
    rep(i, n) data.pb(a[i]);
    SimpleWaveletMatrix w;
    w.init(data);

    rep(x, n) reu(y, x+1, n) {
        int t = 0;
        t -= getcost(x, a[x]);
        t += getcost(x, a[y]);
        t -= getcost(y, a[y]);
        t += getcost(y, a[x]);

        if(a[y] < a[x]) t -= w.rangefreq(x+1, y, a[y]+1, a[x]-1);
        if(a[x] < a[y]) t += w.rangefreq(x+1, y, a[x]+1, a[y]-1);
        if(t < mi) {
            xm = x;
            ym = y;
            mi = t;
        }
    }
    cout << xm << " " << ym << endl;
    cerr << mi << endl;

//  cerr << "before: "<< simu(vi(a,a+n)) << endl;
    swap(a[xm], a[ym]);
//  cerr << "after: " << simu(vi(a,a+n)) << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

/*
int simu(vi a) {
    int n = a.size();
    int r = 0;
    for(int i = 1; i < n; i ++) {
        int j = i;
        while(j > 0 && a[j] < a[j-1]) {
            r ++;
            swap(a[j], a[j-1]);
            j = j - 1;
        }
    }
    return r;
}
*/

int a[5000], cost[5000];
vi sorted[5000];
int getcost(int i, int x) {
    return i - (upper_bound(all(sorted[i]), x) - sorted[i].begin());
}
int main() {
    int n, xm = -1, ym = -1, mi = INF;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        vi v = vi(a, a+i);
        sort(all(v));
        sorted[i] = v;
    }

    rep(x, n) reu(y, x+1, n) {
        int t = 0;
        t -= getcost(x, a[x]);
        t += getcost(x, a[y]);
        t -= getcost(y, a[y]);
        t += getcost(y, a[x]);
        if(t < mi) {
            xm = x;
            ym = y;
            mi = t;
        }
    }
    cout << xm << " " << ym << endl;

//  cerr << "before: "<< simu(vi(a,a+n)) << endl;
//  swap(a[xm], a[ym]);
//  cerr << "after: " << simu(vi(a,a+n)) << endl;
    return 0;
}


#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define pii pair<int, int>
typedef long long LL;
using namespace std;
int a[5005], cnt1[5005][5005], cnt2[5005][5005];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int sum1, sum2, tot = 0;
  for (int i = 1; i <= n; ++i) {
    sum1 = sum2 = 0;
    for (int j = 1; j <= n; ++j) {
      if (a[j] > a[i]) sum1++;
      if (a[j] < a[i]) sum2++;
      cnt1[i][j] = sum1;
      cnt2[i][j] = sum2;
    }
    tot += cnt1[i][i - 1];
  }
  int ans1 = 0, ans2 = 0,  t;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      t = + (cnt1[i][i - 1] - cnt1[i][j]) - (cnt2[i][i - 1] - cnt2[i][j])
          - (cnt1[j][i - 1] - cnt1[j][j]) + (cnt2[j][i - 1] - cnt2[j][j]);
      if (a[i] > a[j]) t--;
      if (a[i] < a[j]) t++;
      if (t == ans1) {
        ans2++;
      } else if (t > ans1) {
        ans1 = t;
        ans2 = 1;
      }
    }
  }
  cout << tot - ans1 << ' ' << ans2;
}


#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define pii pair<int, int>
typedef long long LL;
using namespace std;
int a[5005], cnt1[5005][5005], cnt2[5005][5005];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int sum1, sum2, tot = 0;
  for (int i = 1; i <= n; ++i) {
    sum1 = sum2 = 0;
    for (int j = 1; j <= n; ++j) {
      if (a[j] > a[i]) sum1++;
      if (a[j] < a[i]) sum2++;
      cnt1[i][j] = sum1;
      cnt2[i][j] = sum2;
    }
    tot += cnt1[i][i - 1];
  }
  int ans1 = 0, ans2 = 0,  t;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      t = + (cnt1[i][i - 1] - cnt1[i][j]) - (cnt2[i][i - 1] - cnt2[i][j]);
          - (cnt1[j][i - 1] - cnt1[j][j]) + (cnt2[j][i - 1] - cnt2[j][j]);
      if (a[i] > a[j]) t--;
      if (a[i] < a[j]) t++;
      if (t == ans1) {
        ans2++;
      } else if (t > ans1) {
        ans1 = t;
        ans2 = 1;
      }
    }
  }
  cout << tot - ans1 << ' ' << ans2;
}


#include <bits/stdc++.h>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;
typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const double EPS = 1-9; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = 10 * a + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(int a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[10]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;}

const int N = 100000;

int n;

int t[5000];

int get(int r)
{
    int res = 0;
    for(; r >= 0; r = (r & (r + 1)) - 1)
    {
        res += t[r];
    }
    return res;
}

void add(int pos)
{
    for(; pos < n; pos |= pos + 1)
        t[pos]++;
}

int main()
{
    input(n);

    int a[n];

    int ans = 0;

    for(int i = 0; i < n; ++i)
    {
        a[i] = nxt();
    }

    for(int i = 0; i < n; ++i)
    {
        for(int j = i + 1; j < n; ++j)
        {
            if (a[i] > a[j])
                ++ans;
        }
    }

    int inv = ans;

    int cnt = 0;

    for(int i = 0; i < n; ++i)
    {
        clr(t);
        int cur = inv;
        add(a[i]);
        for(int j = i + 1; j < n; ++j)
        {
            int delta = 2 * get(a[j]) - (j - i - 1);
            if (cur + delta < ans)
            {
                ans = cur + delta;
                cnt = 1;
            }
            else
            {
                if (cur + delta == ans)
                {
                    ++cnt;
                }
            }
            add(a[j]);
            cur += (a[j] > a[i]) ? 1 : -1;
        }
    }

    cout << ans - 1 << " " << cnt << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FOREACH(i,c) FOR(i,0,SIZE(c)-1)
#define FORDEACH(i,c) FORD(i,SIZE(c)-1,0)
#define MIN(x,y) ( ((x) < (y))? (x) : (y) )
#define MAX(x,y) ( ((x) > (y))? (x) : (y) )
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define INF 1000000001

using namespace std;

typedef pair < int , int > PII;
typedef long long int LLI;

typedef vector < int > VI;
typedef vector < bool > VB;
typedef vector < PII > VP;
typedef vector < LLI > VL;

typedef vector < VI > VVI;
typedef vector < VL > VVL;
typedef vector < VB > VVB;

#define par(x) ( (x-1)/2 )

/*************************************************************************/

class ITree
{
private:
    vector < int > T;
    int p;

public:
    ITree(int n) //contructor
    {
        p = 1;
        while (p < n) p *= 2;

        T.resize(2*p-1,0);
    }

    void Insert(int l, int v)
    {
        l += p-1;

        T[l] += v;

        while (l > 0)
        {
            l = par(l);
            T[l] += v;
        }

        return ;
    }

    int Query(int l, int r) //takes interval [l+1,r-1]
    {
        if (l > r) return 0;

        l += p-1;
        r += p-1;

        int ans = T[l];
        if (l < r) ans += T[r];

        while (par(l) != par(r))
        {
            if (l%2 == 1) ans += T[l+1];
            if (r%2 == 0) ans += T[r-1];

            l = par(l);
            r = par(r);
        }

        return ans;
    }
};

/*************************************************************************/

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    VI T(n);
    FOREACH(i,T) cin >> T[i];

    int inv = 0;
    FOR(i,0,n-1) FOR(j,i+1,n-1)
        inv += (T[i] > T[j]);

    VVI decr(n);
    FOREACH(i,decr) decr[i].resize(n,0);

    FOR(i,0,n-1)
    {
        ITree Tree(n);

        FOR(j,i+1,n-1)
        {
            if (T[i] > T[j])
                decr[i][j] = 1 + 2 * Tree.Query(T[j] + 1, T[i] - 1);

            Tree.Insert(T[j], 1);
        }
    }

    int best = 0;
    FOR(i,0,n-1) FOR(j,i+1,n-1)
        best = MAX(best,decr[i][j]);

    cout << inv - best << ' ';

    int cnt = 0;
    FOR(i,0,n-1) FOR(j,i+1,n-1)
        cnt += (decr[i][j] == best);

    cout << cnt;

    return 0;
}

/*************************************************************************/


#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <stdio.h>
#include <string.h>

#define INF (1<<28)
#define LINF (1e17)

using namespace std;

int
calc_val(vector<int> &v,int l,int r) {
	int score=0;
	int p=v[l];
	for (int i=l; i<=r; ++i) {
		if (v[i] > p) {
			++score;
		}
		else {
			--score;
		}
	}
	p=v[r];
	for (int i=l; i<=r; ++i) {
		if (v[i] > p) {
			--score;
		}
		else {
			++score;
		}
	}
	return score;
}

int
main() {
	int N;
	scanf("%d",&N);
	vector<int> v(N);
	for (int i=0; i<N; ++i) {
		scanf("%d",&v[i]);
	}
	int mn = INF;
	int mnc = 0;
	int l=-1,r=-1;
	for (int i=0; i<N; ++i) {
		for (int j=i+1; j<N; ++j) {
			int val = calc_val(v, i, j);
			if (val < mn) {
				mn = val;
				mnc = 1;
				l = i , r = j;
			}
			else if (val == mn) {
				++mnc;
			}
		}
	}

	swap(v[l], v[r]);
	int cnt = 0;
	for (int i=0; i<N; ++i) {
		for (int j=i+1; j<N; ++j) {
			if (v[i] > v[j]) {
				++cnt;
			}
		}
	}
	printf("%d %d\n",cnt,mnc);
	return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <iomanip>

#define INF (1<<30)
#define LINF (5e18)

const double EPS = 1.0e-8;

using namespace std;

int N;
vector<int> d;
vector<vector<int> > dp,dist;

int calc() {
	int cnt = 0;
	for (int i=1; i<N; ++i) {
		int j = i;
		while (j > 0 && d[j-1] > d[j] ) {
			++cnt;
			swap(d[j-1], d[j]);
			--j;
		}
	}
	return cnt;
}

void solve() {
	for (int i=0; i<N; ++i)
		for (int j=i+1; j<N; ++j)
			dist[i][j] = dist[i][j-1] + ( d[i] > d[j] ? -1 : 1 );
	for (int i=N-1; i>=0; --i)
		for (int j=i-1; j>=0; --j)
			dist[i][j] = dist[i][j+1] + ( d[j] > d[i] ? -1 : 1 );

	int mn = 0 , cnt = 1;
	for (int i=0; i<N; ++i) {
		for (int j=i+1; j<N; ++j) {
			int c = dist[i][j] + dist[j][i] + 1;
			if (c < mn) {
				mn = c;
				cnt = 1;
			}
			else if (mn == c) {
				++cnt;
			}
		}
	}

	printf("%d %d\n",calc()+mn,cnt);
}

int main() {
	scanf("%d",&N);

	d.clear();
	d.resize(N);
	dp.clear();
	dp.resize(N,vector<int>(N,0));
	dist.clear();
	dist.resize(N,vector<int>(N,0));

	for (int i=0; i<N; ++i) {
		scanf("%d",&d[i]);
	}
	solve();
}


#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <iomanip>

#define INF (1<<30)
#define LINF (5e18)

const double EPS = 1.0e-8;

using namespace std;

int N;
vector<int> d;
vector<vector<int> > dist;

int calc() {
	int cnt = 0;
	for (int i=1; i<N; ++i) {
		int j = i;
		while (j > 0 && d[j-1] > d[j] ) {
			++cnt;
			swap(d[j-1], d[j]);
			--j;
		}
	}
	return cnt;
}

void solve() {
	for (int i=0; i<N; ++i)
		for (int j=i+1; j<N; ++j)
			dist[i][j] = dist[i][j-1] + ( d[i] > d[j] ? -1 : 1 );
	for (int i=N-1; i>=0; --i)
		for (int j=i-1; j>=0; --j)
			dist[i][j] = dist[i][j+1] + ( d[j] > d[i] ? -1 : 1 );

	int mn = 0 , cnt = 1;
	for (int i=0; i<N; ++i) {
		for (int j=i+1; j<N; ++j) {
			int c = dist[i][j] + dist[j][i] + 1;
			if (c < mn) {
				mn = c;
				cnt = 1;
			}
			else if (mn == c) {
				++cnt;
			}
		}
	}

	printf("%d %d\n",calc()+mn,cnt);
}

int main() {
	scanf("%d",&N);

	d.clear();
	d.resize(N);
	dist.clear();
	dist.resize(N,vector<int>(N,0));

	for (int i=0; i<N; ++i) {
		scanf("%d",&d[i]);
	}
	solve();
}


#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <stdio.h>
#include <string.h>

#define INF (1<<28)
#define LINF (1e17)

using namespace std;

const int MAX = 5005;
int dp[MAX][MAX];

int
main() {
	int N;
	scanf("%d",&N);
	vector<int> v(N);
	for (int i=0; i<N; ++i) {
		scanf("%d",&v[i]);
	}

	memset(dp, 0, sizeof(dp));
	for (int i=0; i<N; ++i) {
		for (int j=i+1; j<N; ++j) {
			if (v[i] < v[j]) {
				dp[i][j] = dp[i][j-1] + 1;
			}
			else if (v[i] > v[j]) {
				dp[i][j] = dp[i][j-1] - 1;
			}
		}
	}
	for (int i=N-1; i>=0; --i) {
		for (int j=i-1; j>=0; --j) {
			if (v[i] < v[j]) {
				dp[i][j] = dp[i][j+1] - 1;
			}
			else if (v[i] > v[j]) {
				dp[i][j] = dp[i][j+1] + 1;
			}
		}
	}

	int mn = INF;
	int mnc = 0;
	int l=-1,r=-1;
	for (int i=0; i<N; ++i) {
		for (int j=i+1; j<N; ++j) {
			int val = dp[i][j] + dp[j][i];
			if (val < mn) {
				mn = val;
				mnc = 1;
				l = i , r = j;
			}
			else if (val == mn) {
				++mnc;
			}
		}
	}

	swap(v[l], v[r]);
	int cnt = 0;
	for (int i=0; i<N; ++i) {
		for (int j=i+1; j<N; ++j) {
			if (v[i] > v[j]) {
				++cnt;
			}
		}
	}
	printf("%d %d\n",cnt,mnc);
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <list>
#include <queue>
#include <map>
#include <ctime>

#define F first
#define S second
#define pb push_back
#define INF 1<<30
#define mp make_pair
#define pi pair<int, int>
#define readString(s) gets(buff);s = buff
#define y1 yyy1
#define y2 yyy2
#define SQR(a) ((a)*(a))

#define swag swap

using namespace std;

const int N = 5555;

int n, m;
int f[N][N];
int f2[N][N];

int main()
{

    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w",stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
    #endif

    int n;
    scanf("%d", &n);

    int v[N];

    for(int i = 1; i<=n; i++)
    {
        scanf("%d", &v[i]);
    }

    for(int i = 1; i<=n; i++)
    {
        for(int j = 0; j<n; j++)
        {
            f[i][j] = f[i-1][j] + (v[i] < j);
            f2[i][j] = f2[i-1][j] + (v[i] > j);
        }
    }

    int cnt = 0;

    for(int i = 1; i<=n; i++)
    {
        for(int j = 1; j<=i; j++)
        {
            if (v[j] > v[i])
                cnt++;
        }
    }

    int mx = INF, mxn = 0;

    for(int i = 1; i<=n; i++)
    {
        for(int j = i+1; j<=n; j++)
        {
            if (v[i] > v[j])
            {
                int k1 = f[j-1][v[i]] - f[i-1][v[i]]; ///number of elements less than v[i] in range from i to j, these no longer count, so should be substracted
                int k2 = f[j-1][v[j]] - f[i-1][v[j]]; ///number of elements less than v[j] in range from i to j, should be added
                int k3 = f2[j-1][v[j]] - f2[i-1][v[j]]; /// number of elements bigger than v[j] in the range, to be subtracted
                int k4 = f2[j-1][v[i]] - f2[i-1][v[i]]; /// number of elements bigger than v[i], to be added
                int d = k2 - k1 + k4 - k3;
                if (mx > d)
                {
                    mx = d;
                    mxn = 0;
                }
                if (mx == d)
                    mxn++;
            }
        }
    }

    printf("%d %d", cnt + mx, mxn);

    return 0;
}


#ifdef ONLINE_JUDGE
	#include <bits/stdc++.h>
#else
	#include <algorithm>
	#include <bitset>
	#include <cassert>
	#include <cstdio>
	#include <cstring>
	#include <iostream>
	#include <map>
	#include <set>
	#include <stack>
	#include <string>
	#include <utility>
	#include <vector>
	#include <cstdlib>
#endif

using namespace std;

	// lambda : [] (int a, int b) -> bool { body return }
	// string r_str = R"(raw string)"

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define LL long long
#define ULL unsigned long long
#define BASE 73
#define NMAX 10000
#define NMAX2 20001
#define MOD1 1000000007
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define CRLINE Duxar(__LINE__);
#define SHOWME(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define ENTER putchar('\n');

int dx4[] = {-1, 0, 1, 0};
int dy4[] = {0, 1, 0, -1};

int dx6[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy6[] = {0, 1, 1, 1, 0, -1, -1, -1};

void Duxar(int _this_line) {
#ifndef ONLINE_JUDGE
	printf("\n . . . . . . . . . . . . . Passed line - %d\n", _this_line);
#endif
}

template <class T>
void ReadNo(T &_value) {
	T _sign = 1;
	char ch;
	_value = 0;
	while(!isdigit(ch = getchar())) {
		(ch == '-') && (_sign = -1);
	}
	do {
		_value = _value * 10 + (ch - '0');
	} while(isdigit(ch = getchar()));
	_value *= _sign;
}

template <class T>
void AddNr(T &a, T b) {
	a = a + b;
	while (a >= MOD1) {
		a -= MOD1;
	}
	while (a < 0) {
		a += MOD1;
	}
}

int N, best, cnt, ans;
vector <int> aib, values;

void Insert(int pos) {
	while (pos <= N) {
		++aib[pos];
		pos += pos & ((pos - 1) ^ pos);
	}
}

int Query(int pos) {
	int ans = 0;
	while (pos > 0) {
		ans += aib[pos];
		pos -= pos & ((pos - 1) ^ pos);
	}
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.cpp", "r", stdin);
#endif

	int i, j, sumi, sumj;
	pair <int, int> pr;

	ReadNo(N);
	values.resize(N + 1);
	aib.resize(N + 1);
	for (i = 1; i <= N; ++i) {
		ReadNo(values[i]);
		++values[i];
	}

	for (i = 1; i < N; ++i) {
		fill(ALL(aib), 0);
		for (j = i; j <= N; ++j) {
			Insert(values[j]);
			sumi = Query(values[i] - 1);
			sumj = Query(values[j] - 1);
			if (sumi - sumj > best) {
				best = sumi - sumj;
				pr = {i, j};
				cnt = 1;
			}
			else if (sumi - sumj == best) {
				++cnt;
			}
		}
	}

	swap(values[pr.first], values[pr.second]);
	fill(ALL(aib), 0);
	for (i = N; i > 0; --i) {
		ans += Query(values[i] - 1);
		Insert(values[i]);
	}

	printf("%d %d\n", ans, cnt);

	return 0;
}


#ifdef ONLINE_JUDGE
	#include <bits/stdc++.h>
#else
	#include <algorithm>
	#include <bitset>
	#include <cassert>
	#include <cstdio>
	#include <cstring>
	#include <iostream>
	#include <map>
	#include <set>
	#include <stack>
	#include <string>
	#include <utility>
	#include <vector>
	#include <cstdlib>
#endif

using namespace std;

	// lambda : [] (int a, int b) -> bool { body return }
	// string r_str = R"(raw string)"

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define LL long long
#define ULL unsigned long long
#define BASE 73
#define NMAX 10000
#define NMAX2 20001
#define MOD1 1000000007
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define CRLINE Duxar(__LINE__);
#define SHOWME(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define ENTER putchar('\n');

int dx4[] = {-1, 0, 1, 0};
int dy4[] = {0, 1, 0, -1};

int dx6[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy6[] = {0, 1, 1, 1, 0, -1, -1, -1};

void Duxar(int _this_line) {
#ifndef ONLINE_JUDGE
	printf("\n . . . . . . . . . . . . . Passed line - %d\n", _this_line);
#endif
}

template <class T>
void ReadNo(T &_value) {
	T _sign = 1;
	char ch;
	_value = 0;
	while(!isdigit(ch = getchar())) {
		(ch == '-') && (_sign = -1);
	}
	do {
		_value = _value * 10 + (ch - '0');
	} while(isdigit(ch = getchar()));
	_value *= _sign;
}

template <class T>
void AddNr(T &a, T b) {
	a = a + b;
	while (a >= MOD1) {
		a -= MOD1;
	}
	while (a < 0) {
		a += MOD1;
	}
}

int N, best, cnt, ans;
vector <int> values;
int aib[5001];

void Insert(int pos) {
	while (pos <= N) {
		++aib[pos];
		pos += pos & ((pos - 1) ^ pos);
	}
}

int Query(int pos) {
	int ans = 0;
	while (pos > 0) {
		ans += aib[pos];
		pos -= pos & ((pos - 1) ^ pos);
	}
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.cpp", "r", stdin);
#endif

	int i, j, sumi, sumj;
	pair <int, int> pr;

	ReadNo(N);
	values.resize(N + 1);
	for (i = 1; i <= N; ++i) {
		ReadNo(values[i]);
		++values[i];
	}

	for (i = 1; i < N; ++i) {
		memset(aib, 0, sizeof(aib));
		for (j = i; j <= N; ++j) {
			Insert(values[j]);
			sumi = Query(values[i] - 1);
			sumj = Query(values[j] - 1);
			if (sumi - sumj > best) {
				best = sumi - sumj;
				pr = {i, j};
				cnt = 1;
			}
			else if (sumi - sumj == best) {
				++cnt;
			}
		}
	}

	swap(values[pr.first], values[pr.second]);
	memset(aib, 0, sizeof(aib));
	for (i = N; i > 0; --i) {
		ans += Query(values[i] - 1);
		Insert(values[i]);
	}

	printf("%d %d\n", ans, cnt);

	return 0;
}


#ifdef ONLINE_JUDGE
	#include <bits/stdc++.h>
#else
	#include <algorithm>
	#include <bitset>
	#include <cassert>
	#include <cstdio>
	#include <cstring>
	#include <iostream>
	#include <map>
	#include <set>
	#include <stack>
	#include <string>
	#include <utility>
	#include <vector>
	#include <cstdlib>
#endif

using namespace std;

	// lambda : [] (int a, int b) -> bool { body return }
	// string r_str = R"(raw string)"

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define LL long long
#define ULL unsigned long long
#define BASE 73
#define NMAX 10000
#define NMAX2 20001
#define MOD1 1000000007
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define CRLINE Duxar(__LINE__);
#define SHOWME(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define ENTER putchar('\n');

int dx4[] = {-1, 0, 1, 0};
int dy4[] = {0, 1, 0, -1};

int dx6[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy6[] = {0, 1, 1, 1, 0, -1, -1, -1};

void Duxar(int _this_line) {
#ifndef ONLINE_JUDGE
	printf("\n . . . . . . . . . . . . . Passed line - %d\n", _this_line);
#endif
}

template <class T>
void ReadNo(T &_value) {
	T _sign = 1;
	char ch;
	_value = 0;
	while(!isdigit(ch = getchar())) {
		(ch == '-') && (_sign = -1);
	}
	do {
		_value = _value * 10 + (ch - '0');
	} while(isdigit(ch = getchar()));
	_value *= _sign;
}

template <class T>
void AddNr(T &a, T b) {
	a = a + b;
	while (a >= MOD1) {
		a -= MOD1;
	}
	while (a < 0) {
		a += MOD1;
	}
}

int N, best, cnt, ans;
vector <int> values;
int aib[5001];

void Insert(int pos) {
	while (pos <= N) {
		++aib[pos];
		pos += pos & (-pos);
	}
}

int Query(int pos) {
	int ans = 0;
	while (pos > 0) {
		ans += aib[pos];
		pos -= pos & (-pos);
	}
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("input.cpp", "r", stdin);
#endif

	int i, j, sumi, sumj;
	pair <int, int> pr;

	ReadNo(N);
	values.resize(N + 1);
	for (i = 1; i <= N; ++i) {
		ReadNo(values[i]);
		++values[i];
	}

	for (i = 1; i < N; ++i) {
		memset(aib, 0, sizeof(aib));
		for (j = i; j <= N; ++j) {
			Insert(values[j]);
			sumi = Query(values[i] - 1);
			sumj = Query(values[j] - 1);
			if (sumi - sumj > best) {
				best = sumi - sumj;
				pr = {i, j};
				cnt = 1;
			}
			else if (sumi - sumj == best) {
				++cnt;
			}
		}
	}

	swap(values[pr.first], values[pr.second]);
	memset(aib, 0, sizeof(aib));
	for (i = N; i > 0; --i) {
		ans += Query(values[i] - 1);
		Insert(values[i]);
	}

	printf("%d %d\n", ans, cnt);

	return 0;
}


#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define PF push front
#define MP make_pair
#define REP(x, n) for(int x=0; x<(n); ++x)
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define VAR(v,n) __typeof(n) v=(n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MOD(x, n) ((x)%(n)+(n))%(n)
#define SZ(x) (int((x).size()))
#define ALL(x) ((x).begin()),((x).end())
#define SORT(v) sort((v).begin(),(v).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define UNIQUE(v) SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())

LL gcd(LL a, LL b) {
    if(b == 0)
        return a;
    return gcd(b,a%b);
}
LL lcm(LL a, LL b) {
    return a*(b/gcd(a, b));
}

typedef vector<int>    VI;
typedef vector<string> VS;
typedef vector<VI>     VVI;
typedef vector<LL>     VLL;
typedef vector<bool>   VB;
typedef vector<double> VD;
typedef vector<VD>     VVD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII>    VPII;
typedef pair<LL, LL>   PLL;
typedef vector<PLL>    VPLL;
typedef vector<VLL>    VVLL;

const double EPS = 1e-9;
const double PI = acos(-1.0);
const int INF = (1LL << 29);

using namespace std;

template<typename T>
string toString(T t) {
    stringstream ss;
    ss << t;
    return ss.str();
}

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int N;
    cin >> N;

    VI a(N, 0);
    REP(i, N) {
        cin >> a[i];
    }

    VVI less(N, VI(N, 0)), more(N, VI(N, 0));
    REP(i, N) {
        FOR(j, 1, N-1) {
            more[i][j] += more[i][j-1]+(a[j-1] > i);
        }
    }

    REP(i, N) {
        FORD(j, N-2, 0) {
            less[i][j] += less[i][j+1]+(a[j+1] < i);
        }
    }

    int cnt = 0, val = INF;
    REP(i, N) {
        REP(j, i) {
            int after = 0, before = 0;
            if(a[i] > a[j])
                after++;
            after += more[a[i]][j]+less[a[i]][j];
            after += less[a[j]][i]+more[a[j]][i];

            if(a[j] > a[i])
                before--;
            before += more[a[i]][i]+less[a[i]][i];
            before += less[a[j]][j]+more[a[j]][j];

            if(val > after-before) {
                val = after-before;
                cnt = 1;
            } else if(val == after-before) {
                cnt++;
            }
        }
    }

    REP(i, N) {
        REP(j, i) {
            if(a[i] < a[j]) {
                val++;
            }
        }
    }

    cout << val << " " << cnt << endl;
    return 0;
}


// به نام خدا
#pragma comment(linker,"/STACK:100000000,100000000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <limits.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define rep(i, n) for(ll i = 0; i < n; i++)
#define F first
#define S second
#define pll pair<ll, ll>
#define mp make_pair
typedef long long ll;
ll max(ll x,ll y){return x>y?x:y;} ll min(ll x,ll y){return x<y?x:y;}
using namespace std;

/*
              (O)
             <M
  o          <M
 /| ......  /:M\------------------------------------------------,,,,,,
 (O)[]Koorosh[]I:K+}=====<{H}>================================------------>
 \| ^^^^^^  \:W/------------------------------------------------''''''
  o          <W
             <W
              (O)
 */

const ll N = 1e5 + 9;

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

int main()
{_
    ll n;
    ll a[N];
    cin >> n;
    rep(i, n) cin >> a[i];

    ll ans = -10000, op = 0, cnt = 0;
    rep(i, n)
        rep(j, n) {
            ll pre = abs(a[i] - i) + abs(a[j] - j);
            ll aft = abs(a[i] - j) + abs(a[j] - i);
            ans = max(ans, pre - aft);
        }

    rep(i, n)
        rep(j, n) {
            ll pre = abs(a[i] - i) + abs(a[j] - j);
            ll aft = abs(a[i] - j) + abs(a[j] - i);
            if (pre - aft == ans) cnt++;
        }

    for (int i = 1; i < n; i = i + 1)   {
        int j = i;
        while (j > 0 && a[j] < a[j - 1])
        {
            swap(a[j], a[j - 1]);
            j = j - 1;
            op++;
        }
    }
    cout << op - ans + 1 << ' ' << cnt / 2;
}


#include<bits/stdc++.h>
using namespace std;

const int N = 5000;
int f[N + 1][N + 1], n, a[N];

int main() {
	cin >> n; for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			f[i][j] = f[i - 1][j] + (a[i - 1] < j ? 1 : 0);
	int numInverse = 0;
	for(int i = 0; i < n; ++i)
		for(int j = i + 1; j < n; ++j)
			if(a[i] > a[j]) ++numInverse;
	int res = numInverse, cnt = 0;
	for(int i = 0; i < n; ++i)
		for(int j = i + 1; j < n; ++j)
			if(a[i] > a[j]) {
				int newInverse = numInverse;
				newInverse += f[j][a[j]] - f[i + 1][a[j]];
				newInverse += j - (i + 1) - (f[j][a[i]] - f[i + 1][a[i]]);
				newInverse -= j - (i + 1) - (f[j][a[j]] - f[i + 1][a[j]]);
				newInverse -= f[j + 1][a[i]] - f[i][a[i]];
				if(newInverse < res) res =  newInverse, cnt = 1;
				else if(newInverse == res) ++cnt;
			}
	cout << res << ' ' << cnt << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int INF = 1000 * 1000 * 1000;
const int N = 5555;

int f[N][N];
int a[N];
int n;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            f[i][j] = a[j] > i ? 1 : 0;
            if (j)
                f[i][j] += f[i][j - 1];
        }
    /*for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            int s = 0;
            for (int k = 0; k <= j; k++)
                if (a[k] > i)
                    s++;
            assert(s == f[i][j]);
        }*/
    int best = INF;
    int cnt = 0;
    int x, y;
    for (int l = 0; l < n; l++)
        for (int r = l + 1; r < n; r++)
        {
            int vl = a[l];
            int vr = a[r];
            int bigL = f[vl][r] - f[vl][l];
            int smallL = r - l - bigL;
            int bigR = f[vr][r] - f[vr][l];
            int smallR = r - l - bigR;
            int cur = 0;
            cur -= smallL;
            cur += bigL;
            cur += smallR;
            cur -= bigR;
            if (vl > vr)
                cur--;
            if (cur < best)
            {
                best = cur;
                x = l;
                y = r;
                cnt = 1;
            }
            else if (cur == best)
            {
                cnt++;
            }
        }

    swap(a[x], a[y]);
    int tot = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < i; j++)
            if (a[j] > a[i])
                tot++;

    cout << tot << " " << cnt;

    return 0;
}


#include <iostream>

using namespace std;

#define MAXN 5010

int N[MAXN][MAXN];
int a[MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];

    long long inv = 0;
    long long cnt = 0;
    long long invm = 6000*6000;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            N[i][j] = a[j] < i ? 1 : 0;
            if(i < j && a[i] > a[j]) inv++;
        }
//        for(int j = 0; j < n; j++)
//            cout << N[i][j] << " ";
//        cout << endl;
        for(int j = 1; j < n; j++)
            N[i][j] += N[i][j - 1];

    }
//    for(int i = 0; i < n; i++) {
//        for(int j = 0; j < n; j++)
  //          cout << N[i][j] << " ";
//        cout << endl;}
//        cout << inv << endl;
    for(int i = 0; i < n; i++)
        for(int j = i + 1; j < n; j++) {
            long long diff = a[i] > a[j] ? -1 : 0;
            diff -= N[a[i]][j - 1] - N[a[i]][i];
            diff += N[a[j]][j - 1] - N[a[j]][i];
            diff -= j - i - 1 - (N[a[j]][j - 1] - N[a[j]][i]);
            diff += j - i - 1 - (N[a[i]][j - 1] - N[a[i]][i]);
            long long invr = inv + diff;
//            cout << i << " " << j << " : " << invr << " " << diff << endl;//<< " " << inv_ii << " " << inv_jj << " " << inv_ij << " " << inv_ji << endl;
            if(invr <= invm) {
                if(invr < invm) {
                    invm = invr;
                    cnt = 0;
                }
                cnt++;
            }
        }
    cout << invm << " " << cnt << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(x,n) for(int x=0;x<int(n);++x)
#define print(x) cout<<x<<endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define pv(x,y) {for(typeof(y) z=(x);z!=(y);z++)cerr<<*z<<" ";cerr<<endl;}
#define _ <<" , "<<
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef pair<int,int> pt;

int a[5555], n;

int main() {
  if(true) cin.sync_with_stdio(false);
  cin>>n;

  int fmin=0,cnt=1;

  rep(i,n) {
    cin>>a[i];
    fmin += abs(a[i]-i);
  }

  int pre=fmin;

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++) {
      int opa=pre;
      opa -= abs(a[i]-i);
      opa -= abs(a[j]-j);
      opa += abs(a[i]-j);
      opa += abs(a[j]-i);
      if(opa<fmin) fmin=opa,cnt=0;
      if(opa==fmin) cnt++;
    }
  }

  assert(fmin%2 == 0);

  assert(fmin < pre);

  print(fmin/2 << " " << cnt);

  return 0;
}


#include <bits/stdc++.h>
#define rep(x,n) for(int x=0;x<int(n);++x)
#define print(x) cout<<x<<endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define pv(x,y) {for(typeof(y) z=(x);z!=(y);z++)cerr<<*z<<" ";cerr<<endl;}
#define _ <<" , "<<
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef pair<int,int> pt;

int a[5555], n;
int f[5555];

int main() {
  if(true) cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n) {
    cin>>a[i];
    f[a[i]]=i;
  }

  int fmin=0,cnt=1;
  for(int i=0;i<n;i++) fmin+=abs(i-f[i]);

  int pre=fmin;

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++) {
      int opa=pre;
      opa -= abs(i-f[i]);
      opa -= abs(j-f[j]);
      opa += abs(i-f[j]);
      opa += abs(j-f[i]);
      if(opa<fmin) fmin=opa,cnt=0;
      if(opa==fmin) cnt++;
    }
  }

  assert(fmin%2 == 0);

  print(fmin/2 << " " << cnt);

  return 0;
}


#include <bits/stdc++.h>
#define rep(x,n) for(int x=0;x<int(n);++x)
#define print(x) cout<<x<<endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define pv(x,y) {for(typeof(y) z=(x);z!=(y);z++)cerr<<*z<<" ";cerr<<endl;}
#define _ <<" , "<<
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef pair<int,int> pt;

int a[5555], n;

int main() {
  if(true) cin.sync_with_stdio(false);
  cin>>n;

  int fmin=0,cnt=1;

  rep(i,n) {
    cin>>a[i];
    fmin += abs(a[i]-i);
  }

  int pre=fmin;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) if(j!=i) {
      int opa=pre;
      opa -= abs(a[i]-i);
      opa -= abs(a[j]-j);
      opa += abs(a[i]-j);
      opa += abs(a[j]-i);
      if(opa<fmin) fmin=opa,cnt=0;
      if(opa==fmin) cnt++;
    }
  }

  assert(fmin%2 == 0);

  print(fmin/2 << " " << cnt);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vp;
const int inf = 1e9;
const ll INF = 1e18;
const db eps = 1e-10;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define mem(a) memset(a, 0, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(b))
#define PA cout << "pass\n"
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define TM cout << db(clock()) / CLOCKS_PER_SEC << '\n'

const int maxn = 1e5 + 233;
int f[maxn];
ll x[maxn];
vi G[maxn];
int dep[maxn];
int n;
const int mod = 1e9 + 7;

void dfs(int u, int fa){
    dep[u] = dep[fa] + 1;
    if(__gcd(x[u], x[fa]) != x[u]) f[u] = fa;
    else f[u] = f[fa];
    for(auto &v : G[u]){
        if(v == fa) continue;
        dfs(v, u);
    }
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        G[u].eb(v);
        G[v].eb(u);
    }
    dfs(1, 0);
    ll res = 0;
    for(int i = 1; i <= n; i++){
        int p = i;
        ll now = x[p];
        while(p){
            int fp = f[p];
            res = (res + now % mod * (dep[p] - dep[fp])) % mod;
            p = f[p];
            now = __gcd(now, x[p]);
        }
    }
    cout << res << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vp;
const int inf = 1e9;
const ll INF = 1e18;
const db eps = 1e-10;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define mem(a) memset(a, 0, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(b))
#define PA cout << "pass\n"
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define TM cout << db(clock()) / CLOCKS_PER_SEC << '\n'

const int maxn = 1e5 + 233;
int f[maxn][20];
ll g[maxn][20];
ll x[maxn];
vi G[maxn];
int dep[maxn];
int n;
const int mod = 1e9 + 7;

void dfs(int u, int fa){
    dep[u] = dep[fa] + 1;
    g[u][0] = __gcd(x[u], x[fa]);
    f[u][0] = fa;
    for(int i = 1; i < 20; i++) g[u][i] = __gcd(g[u][i - 1], g[f[u][i - 1]][i - 1]), f[u][i] = f[f[u][i - 1]][i - 1];

    for(auto &v : G[u]){
        if(v == fa) continue;
        dfs(v, u);
    }
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        G[u].eb(v);
        G[v].eb(u);
    }
    dfs(1, 0);
    ll res = 0;
    for(int i = 1; i <= n; i++){
        int p = i;
        ll now = x[p];
        while(p){
            int t = p;
            for(int i = 19; i >= 0; i--){
                if(__gcd(now, g[p][i]) == now) p = f[p][i];
            }
            p = f[p][0];
            res = (res + now % mod * (dep[t] - dep[p])) % mod;
            now = __gcd(now, x[p]);
        }
    }
    cout << res << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vp;
const int inf = 1e9;
const ll INF = 1e18;
const db eps = 1e-10;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define mem(a) memset(a, 0, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(b))
#define PA cout << "pass\n"
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define TM cout << db(clock()) / CLOCKS_PER_SEC << '\n'

const int maxn = 1e5 + 233;
int f[maxn];
ll x[maxn];
vi G[maxn];
int dep[maxn];
int n;
const int mod = 1e9 + 7;

void dfs(int u, int fa){
    dep[u] = dep[fa] + 1;
    int p = fa;
    ll now = x[u];

    while(p){
        now = __gcd(now, x[p]);
        if(now != x[u]) {
            f[u] = p;
            break;
        }
        p = f[p];
    }

    for(auto &v : G[u]){
        if(v == fa) continue;
        dfs(v, u);
    }
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        G[u].eb(v);
        G[v].eb(u);
    }
    dfs(1, 0);
    ll res = 0;
    for(int i = 1; i <= n; i++){
        int p = i;
        ll now = x[p];
        while(p){
            if(now == 1){
                res = (res + dep[p]) % mod;
                break;
            }
            int fp = f[p];
            res = (res + now % mod * (dep[p] - dep[fp])) % mod;
            p = f[p];
            now = __gcd(now, x[p]);
        }
    }
    cout << res << '\n';
    return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(tr1::unordered_map<ll,int> hs,int u,int f){
	tr1::unordered_map<ll,int> hs1;
	for(tr1::unordered_map<ll,int>::iterator it=hs.begin();it!=hs.end();it++){
		ll t=gcd(a[u],it->first);
		int y=it->second;
		hs1[t]++;
		sum=(sum+1ll*t*y)%mod;
	}
	hs1[a[u]]++;
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(hs1,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	tr1::unordered_map<ll,int> hs;
	dfs(hs,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}


//
//  Author: bin
//  Created:2019/12/19 14:00:55
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+3,mod=1e9+7;

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
int n;
ll a[N];
vector<vector<int> > G(N);
ll sum=0;

void dfs(vector<pair<ll,int> > vc,int u,int f){
	vector<pair<ll,int> > vv;
	vv.push_back(make_pair(a[u],1));
	for(int i=0;i<vc.size();i++){
		ll x=vc[i].first;
		int y=vc[i].second;
		ll t=gcd(x,a[u]);
		if(vv.back().first==t){
			vv.back().second+=y;
		}
		else{
			vv.push_back(make_pair(t,y));
		}
		sum=(sum+1ll*t*y)%mod;
	}
	swap(vc,vv);
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==f) continue;
		dfs(vc,v,u);
	}
}

int solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=1ll*(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<pair<ll,int> > vc;
	dfs(vc,1,-1);
	printf("%lld\n",sum);
	return 0;
}

signed main(){
	solve();
	return 0;
}