import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val n = f.readLine().toInt()
	val array = f.readLine().split(" ").map{it.toInt()+1}

	val bits = IntArray(n+1)

	fun update(ii : Int, x : Int){
		var i = ii
		while(i <= n){
			bits[i] += x
			i += (i and -i)
		}
	}

	fun psum(ii : Int): Int{
		var i = ii
		var sum : Int = 0
		while(i > 0){
			sum += bits[i]
			i -= (i and -i)
		}
		return sum
	}

	//get initial inversion count
	var initial = 0
	for(k in 0 until n){
		for(j in 0 until k){
			if(array[j] > array[k]) initial++
		}
	}
	println(initial)
	val freq = IntArray(initial+1)
	var min = initial

	//find maximum decrease

	for(k in 0 until n){
		bits.fill(0)
		update(array[k],1)
		for(j in k+1 until n){
			if(array[j] < array[k]){
				//consider swapping
				var i = initial
				//add number > array[k] in the range
				i += psum(n) - psum(array[k])
				//subtract number less than array[j] in range
				i -= psum(n) - psum(array[j])
				i -= psum(array[k]-1)-psum(array[j])

				println("$k $j ${psum(n) - psum(array[k])} ${psum(n) - psum(array[j])} ${psum(array[k]-1)-psum(array[j])}")
				if(i <= initial){
					freq[i]++
					min = min(min,i)
				}
			}
			update(array[j],1)
		}
	}

	println("${min} ${freq[min]}")

}


//Solution by Miras Myrzakerey
//Look at my code
//My code is amazing

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <iomanip>

using namespace std;

#define INF 1000000001
#define sqr(x) (x) * (x)
#define maxn 6000
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.length())
#define F first
#define S second
#define pii pair<int,int>
#define LL long long
#define vi vector<int>
#define forn(xx,yy,zz) for(int zz = xx; zz <= yy; ++zz)
#define forl(xx,yy,zz) for(int zz = xx; zz >= yy; --zz)
#define str string
#define eps 1e-7
#define pi M_PI
#define sz(x) (int)x.size()
#define fill(x,v) memset(x, (v), sizeof(x))

int n, a[maxn], t[4 * maxn], ans[2][maxn][maxn];
LL mn = INF;

void build(int tl, int tr, int v)
{
    if (tl == tr)
        t[v] = a[tl];
    else
    {
        int td = (tl + tr) >> 1;

        build(tl, td, v + v + 1);
        build(td + 1, tr, v + v + 2);

        t[v] = t[v + v + 1] + t[v + v + 2];
    }
}

int get(int tl, int tr, int v, int l, int r)
{
    if (l > r)
        return 0;

    if (tl == l && tr == r)
        return t[v];

    int td = (tl + tr) >> 1;

    return get(tl, td, v + v + 1, l, min(r, td)) + get(td + 1, tr, v + v + 2, max(l, td + 1), r);
}

void update(int tl, int tr, int v, int pos, int val)
{
    if (tl == tr)
        t[v] = val;
    else
    {
        int td = (tl + tr) >> 1;

        if (pos <= td)
            update(tl, td, v + v + 1, pos, val);
        else
            update(td + 1, tr, v + v + 2, pos, val);

        t[v] = t[v + v + 1] + t[v + v + 2];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
    #endif

    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    for (int i = n - 1; i >= 0; --i)
    {
        for (int j = 0; j < n; ++j)
            ans[0][j][i] = get(0, n - 1, 0, 0, j - 1);

        update(0, n - 1, 0, a[i], 1);
    }

    for (int i = 0; i < n; ++i)
        update(0, n - 1, 0, i, 0);

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
            ans[1][j][i] = get(0, n - 1, 0, j + 1, n - 1);

        update(0, n - 1, 0, a[i], 1);
    }

    LL total = 0, anscnt = 0;
    for (int i = 0; i < n; ++i)
        total += ans[0][a[i]][i];

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
        {
            LL cnt = total;

            cnt -= ans[0][a[j]][j];
            cnt += ans[0][a[j]][i];
            cnt -= ans[0][a[i]][i];
            cnt += ans[0][a[i]][j];
            cnt -= ans[1][a[i]][i];
            cnt += ans[1][a[i]][j];
            cnt -= ans[1][a[j]][j];
            cnt += ans[1][a[j]][i];

            if (i < j && a[i] > a[j])
                ++cnt;
            if (i > j && a[i] < a[j])
                ++cnt;

            if (cnt < mn)
            {
                mn = cnt;
                anscnt = 1;
            }
            else
                if (cnt == mn)
                    ++anscnt;
        }

    cout << mn << ' ' << anscnt << endl;
}


//Solution by Miras Myrzakerey
//Look at my code
//My code is amazing

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <iomanip>

using namespace std;

#define INF 1000000001
#define sqr(x) (x) * (x)
#define maxn 5000
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.length())
#define F first
#define S second
#define pii pair<int,int>
#define LL long long
#define vi vector<int>
#define forn(xx,yy,zz) for(int zz = xx; zz <= yy; ++zz)
#define forl(xx,yy,zz) for(int zz = xx; zz >= yy; --zz)
#define str string
#define eps 1e-7
#define pi M_PI
#define sz(x) (int)x.size()
#define fill(x,v) memset(x, (v), sizeof(x))

int n, a[maxn], t[4 * maxn], ans[2][maxn][maxn];
LL mn = INF;

void build(int tl, int tr, int v)
{
    if (tl == tr)
        t[v] = a[tl];
    else
    {
        int td = (tl + tr) >> 1;

        build(tl, td, v + v + 1);
        build(td + 1, tr, v + v + 2);

        t[v] = t[v + v + 1] + t[v + v + 2];
    }
}

int get(int tl, int tr, int v, int l, int r)
{
    if (l > r)
        return 0;

    if (tl == l && tr == r)
        return t[v];

    int td = (tl + tr) >> 1;

    return get(tl, td, v + v + 1, l, min(r, td)) + get(td + 1, tr, v + v + 2, max(l, td + 1), r);
}

void update(int tl, int tr, int v, int pos, int val)
{
    if (tl == tr)
        t[v] = val;
    else
    {
        int td = (tl + tr) >> 1;

        if (pos <= td)
            update(tl, td, v + v + 1, pos, val);
        else
            update(td + 1, tr, v + v + 2, pos, val);

        t[v] = t[v + v + 1] + t[v + v + 2];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
    #endif

    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    for (int i = n - 1; i >= 0; --i)
    {
        for (int j = 0; j < n; ++j)
            ans[0][j][i] = get(0, n - 1, 0, 0, j - 1);

        update(0, n - 1, 0, a[i], 1);
    }

    for (int i = 0; i < n; ++i)
        update(0, n - 1, 0, i, 0);

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
            ans[1][j][i] = get(0, n - 1, 0, j + 1, n - 1);

        update(0, n - 1, 0, a[i], 1);
    }

    LL total = 0, anscnt = 0;
    for (int i = 0; i < n; ++i)
        total += ans[0][a[i]][i];

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
        {
            LL cnt = total;

            cnt -= ans[0][a[j]][j];
            cnt += ans[0][a[j]][i];
            cnt -= ans[0][a[i]][i];
            cnt += ans[0][a[i]][j];
            cnt -= ans[1][a[i]][i];
            cnt += ans[1][a[i]][j];
            cnt -= ans[1][a[j]][j];
            cnt += ans[1][a[j]][i];

            if (i < j && a[i] > a[j])
                ++cnt;
            if (i > j && a[i] < a[j])
                ++cnt;

            if (cnt < mn)
            {
                mn = cnt;
                anscnt = 1;
            }
            else
                if (cnt == mn)
                    ++anscnt;
        }

    cout << mn << ' ' << anscnt << endl;
}


//Solution by Miras Myrzakerey
//Look at my code
//My code is amazing

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <iomanip>

using namespace std;

#define INF 1000000001
#define sqr(x) (x) * (x)
#define maxn 5000
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.length())
#define F first
#define S second
#define pii pair<int,int>
#define LL long long
#define vi vector<int>
#define forn(xx,yy,zz) for(int zz = xx; zz <= yy; ++zz)
#define forl(xx,yy,zz) for(int zz = xx; zz >= yy; --zz)
#define str string
#define eps 1e-7
#define pi M_PI
#define sz(x) (int)x.size()
#define fill(x,v) memset(x, (v), sizeof(x))

int n, a[maxn], ans[2][maxn][maxn], f[maxn];
LL mn = INF;

int get(int r)
{
    int res = 0;

    for (int i = r; i >= 0; i = (i & (i + 1)) - 1)
        res += f[i];

    return res;
}

int sum(int l, int r)
{
    return get(r) - get(l - 1);
}

void upd(int r, int v)
{
    for (int i = r; i <= n; i = (i | (i + 1)))
        f[i] += v;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
    #endif

    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    for (int i = n - 1; i >= 0; --i)
    {
        for (int j = 0; j < n; ++j)
            ans[0][j][i] = sum(0, j - 1);

        upd(a[i], 1);
    }

    for (int i = 0; i < n; ++i)
        upd(i, -1);

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
            ans[1][j][i] = sum(j + 1, n - 1);

        upd(a[i], 1);
    }

    LL total = 0, anscnt = 0;
    for (int i = 0; i < n; ++i)
        total += ans[0][a[i]][i];

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
        {
            LL cnt = total;

            cnt -= ans[0][a[j]][j];
            cnt += ans[0][a[j]][i];
            cnt -= ans[0][a[i]][i];
            cnt += ans[0][a[i]][j];
            cnt -= ans[1][a[i]][i];
            cnt += ans[1][a[i]][j];
            cnt -= ans[1][a[j]][j];
            cnt += ans[1][a[j]][i];

            if (i < j && a[i] > a[j])
                ++cnt;
            if (i > j && a[i] < a[j])
                ++cnt;

            if (cnt < mn)
            {
                mn = cnt;
                anscnt = 1;
            }
            else
                if (cnt == mn)
                    ++anscnt;
        }

    cout << mn << ' ' << anscnt << endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <set>
#include <memory>
#include <vector>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <bitset>

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)
#define debug(v) (cout << #v << ": " << v << endl)

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
template <typename T> void print_container(ostream& os, const T& c) { const char* _s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) cout << _s; } } }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const set<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const deque<T>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }

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()); }

template <typename T> void print(T a, int n, const string& split = " ") { for (int i = 0; i < n; i++) { cout << a[i]; if (i + 1 != n) cout << split; } cout << endl; }
template <typename T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
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 = -1;
    int p, q;
    rep(j, n) rep(i, j)
    {
        if (a[i] > a[j])
        {
            int reduce = (sum[j][a[i]] - sum[i][a[i]]) - (sum[j][a[j]] - sum[i][a[j]]);
            if (reduce > max_reduce)
            {
                max_reduce = reduce;
                p = i, q = j;
            }
        }
    }
    printf("%d %d\n", p, q);
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <set>
#include <memory>
#include <vector>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <bitset>

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)
#define debug(v) (cout << #v << ": " << v << endl)

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
template <typename T> void print_container(ostream& os, const T& c) { const char* _s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) cout << _s; } } }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const set<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const deque<T>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }

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()); }

template <typename T> void print(T a, int n, const string& split = " ") { for (int i = 0; i < n; i++) { cout << a[i]; if (i + 1 != n) cout << split; } cout << endl; }
template <typename T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
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;
    int p, q;
    rep(j, n) rep(i, j)
    {
        int reduce = (sum[j][a[i]] - sum[i][a[i]]) - (sum[j][a[j]] - sum[i][a[j]]);
        if (reduce > max_reduce)
        {
            max_reduce = reduce;
            num = 0;
            p = i, q = j;
        }
        if (reduce == max_reduce)
            num++;
    }
    swap(a[p], a[q]);

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


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <set>
#include <memory>
#include <vector>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <bitset>

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)
#define debug(v) (cout << #v << ": " << v << endl)

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
template <typename T> void print_container(ostream& os, const T& c) { const char* _s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) cout << _s; } } }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const set<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& c) { print_container(os, c); return os; }
template <typename T> ostream& operator<<(ostream& os, const deque<T>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& c) { print_container(os, c); return os; }
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }

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()); }

template <typename T> void print(T a, int n, const string& split = " ") { for (int i = 0; i < n; i++) { cout << a[i]; if (i + 1 != n) cout << split; } cout << endl; }
template <typename T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; }
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 = 0;
    int p, q;
    rep(j, n) rep(i, j)
    {
        if (a[i] > a[j])
        {
            int reduce = (sum[j][a[i]] - sum[i][a[i]]) - (sum[j][a[j]] - sum[i][a[j]]);
            if (reduce > max_reduce)
            {
                max_reduce = reduce;
                p = i, q = j;
            }
        }
    }
    printf("%d %d\n", p, q);
}


#include <bits/stdc++.h>
using namespace std;
#define d(a) cerr<<">>>>DEBUG: "<< #a << " = " << (a) << endl
#define deb d("kobakinikobakini\n")
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

int main()
{
    //freopen("i.in","r",stdin);
    //freopen("o.out","w",stdout);
    int n; cin >> n; int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];

    int lo[n][n], hi[n][n];
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            lo[i][j] = hi[i][j] = 0;

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
            lo[i][j] = ((j > 0) ? (lo[i][j-1]) : 0) + ((a[j] < a[i]) ? 1 : 0);
        for(int j = 0; j < n; ++j)
            hi[i][j] = ((j > 0) ? (hi[i][j-1]) : 0) + ((a[j] > a[i]) ? 1 : 0);
    }

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

    int ans = nn, num = 1;
    for(int i = 0; i < n; ++i)
        for(int j = i+1; j < n; ++j)
        {
            int numinv = nn;
            numinv -= (lo[i][j] - lo[i][i]) + (hi[j][j] - hi[j][i]);
            numinv += (hi[i][j] - hi[i][i]) + (lo[j][j] - lo[j][i]);
            if(ans > numinv) ans = numinv, num = 1;
            else if(ans == numinv) ++num;
        }

    cout << ans << ' ' << num << '\n';
    return 0;
}


#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

#define ZERO(v) memset((v), 0, sizeof (v))

const int MAXN = 5001;

int n;

struct Loga {
  Loga() { ZERO(arr); }

  void add(int p) {
    for (++p; p <= n; p += p&-p) {
      ++arr[p];
    }
  }

  int query(int p) const {
    int ans = 0;
    for (++p; p > 0; p -= p&-p) {
      ans += arr[p];
    }
    return ans;
  }

  short arr[MAXN+1];
};

int main() {
  cin.sync_with_stdio(0);

  cin >> n;
  vector<int> perm(n);
  for (int &x : perm) {
    cin >> x;
  }

  int initial = 0;
  {
    Loga loga;
    for (int i=0; i<n; ++i) {
      initial += i - loga.query(perm[i]);
      loga.add(perm[i]);
    }
  }
  // debug(initial);

  int ans = initial, anscnt = 0;
  for (int i=0; i<n; ++i) {
    Loga loga;
    int B = perm[i];
    int qb = 0;
    for (int j=i+1; j<n; ++j) {
      int A = perm[j];
      if (A < B) {
        int qa = loga.query(A);
        int swaps = initial - 1 - 2 * (qb - qa);
        if (swaps < ans) {
          ans = swaps;
          anscnt = 1;
        } else if (swaps == ans) {
          ++anscnt;
        }
      }
      loga.add(A);
      qb += A < B;
    }
  }
  cout << ans << ' ' << anscnt << '\n';
  return 0;
}


#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <vector>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long       LL;
typedef pair<int, int>  PII;
typedef pair<LL, LL>    PLL;
typedef vector<int>     VI;
typedef vector<LL>      VL;
typedef vector<PII>     VPII;
typedef vector<PLL>     VPLL;
#define MM(a,x) memset(a,x,sizeof(a));
#define ALL(x)  (x).begin(), (x).end()
#define P(x)	cerr<<"["#x<<" = "<<(x)<<"]\n"
#define PP(x,i)	cerr<<"["#x<<i<<" = "<<x[i]<<"]\n"
#define P2(x,y)	cerr<<"["#x" = "<<(x)<<", "#y" = "<<(y)<<"]\n"
#define TM(a,b)	cerr<<"["#a" -> "#b": "<<1e3*(b-a)/CLOCKS_PER_SEC<<"ms]\n";
#define FOR(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define rep(i, n) for(int i = 0; i < n; i++)
#define UN(v) sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define x first
#define y second
struct _ {_() {ios_base::sync_with_stdio(0);}} _;
template<class T> void PV(T a, T b) {while(a != b)cout << *a++, cout << (a != b ? " " : "\n");}
template<class T> inline bool chmin(T &a, T b) {return a > b ? a = b, 1 : 0;}
template<class T> inline bool chmax(T &a, T b) {return a < b ? a = b, 1 : 0;}
template<class T> string tostring(T x, int len = 0) {stringstream ss; ss << x; string r = ss.str(); if(r.length() < len) r = string(len - r.length(), '0') + r; return r;}
template<class T> void convert(string x, T& r) {stringstream ss(x); ss >> r;}
template<class A, class B> ostream& operator<<(ostream &o, pair<A, B> t) {o << "(" << t.x << ", " << t.y << ")"; return o;}
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int N = 5555;

int n;
int d[N];
int dp[N][N];

int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> d[i];

	int r1 = 0;
	for(int i = 0; i < n; i++)
		for(int j = i + 1; j < n; j++)
			if(d[i] > d[j]) r1++;

	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= i; j++) dp[i][d[j]] = 1;
		for(int j = 1; j < n; j++) dp[i][j] += dp[i][j - 1];
	}

	int mx = -1, r2 = 0;
	for(int i = 0; i < n; i++)
		for(int j = i + 1; j < n; j++) {
			int l = d[i], r = d[j];
			if(l < r) continue;
			int rInc = dp[j - 1][r] - dp[i][r];
			int rDec = (dp[j - 1][n - 1] - dp[j - 1][r]) - (dp[i][n - 1] - dp[i][r]);
			int lInc = (dp[j - 1][n - 1] - dp[j - 1][l]) - (dp[i][n - 1] - dp[i][l]);
			int lDec = dp[j - 1][l] - dp[i][l];
			int t = rDec + lDec - rInc - lInc;
			if(mx == t) {
				r2++;
			} else if(mx < t) {
				mx = t;
				r2 = 1;
			}
		}
	cout << r1 - mx - 1 << " " << r2 << endl;
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
const int N = 5009;

int a[N];
int sw[N][N];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    int sum = 0;
    for(int i = 0; i < n; ++i){
        sw[i][0] = 0;
        //if(i==a[0]) sum
        for(int j = 1; j < n; ++j){
            sw[i][j] = sw[i][j-1];
            sw[i][j] += i < a[j-1];
            if(i==a[j]) sum += sw[i][j];
            //cout<<i<<' '<<j<<"  "<<sw[i][j]<<endl;
        }
    }

    int ans1 = sum+2, ans2 = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < i; ++j){
            if(i==j) continue;
            int tmp = sum + 2*(sw[a[j]][i] + sw[a[i]][j] - sw[a[i]][i] - sw[a[j]][j])+1;
            //cout<<i<<"  "<<j<<"  "<<
            if(tmp==ans1) ++ans2;
            else if(tmp < ans1){
                ans1 = tmp;
                ans2 = 1;
            }
        }
    }
    printf("%d %d\n", ans1, ans2);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include<iostream>

using namespace std;

#ifdef DEBUG
int _msg_indent,_msg_cnt;
#define msg_head cerr.width(4),cerr<<_msg_cnt++<<__FUNCTION__<<'('<<__LINE__<<')'
#define msg(x) msg_head<<x<<endl
#else
#define msg(x)
#endif

template<typename T>
inline void maximize(T& a,const T b)
{ if (b>a) a=b; }
template<typename T>
inline void minimize(T& a,const T b)
{ if (b<a) a=b; }
template<typename T>
inline T maximum(const T& a,const T& b)
{ return a>b?a:b; }
template<typename T>
inline T minimum(const T& a,const T& b)
{ return a<b?a:b; }

typedef long long ll;

int scan(){
    char ch; bool neg = 0;
    while (!isdigit(ch=getchar()))
        neg |= (ch == '-');
    int x=ch-'0';
    while (isdigit(ch=getchar()))
        x=x*10+ch-'0';
    return neg?-x:x;
}

int n, a[5007], ans, cnt, rev, z[5007][5007];

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

void work() {
    ans = cnt = 0;
    for (int r = 1; r < n; ++r) {
        int c = 0;
        for (int l = 0; l < r; ++l)
            if (a[l] < a[r]) ++c;
        for (int l = 0; l < r; ++l) {
            if (a[l] < a[r]) --c;
            z[l][r] += (r-l-1) - 2*c;
            if (a[l] > a[r]) ++z[l][r];
            msg(l<<' '<<r<<' '<<z[l][r]<<' '<<c);
        }
    }
    for (int l = n-2; l >=0; --l) {
        int c = 0;
        for (int r = n-1; l < r; --r)
            if (a[l] < a[r]) ++c;
        for (int r = n-1; l < r; --r) {
            if (a[l] < a[r]) --c;
            z[l][r] += (r-l-1) - 2*c;
            msg(l<<' '<<r<<' '<<z[l][r]<<' '<<c);
        }
    }
    for (int l = 0; l < n-1; ++l)
        for (int r = l+1; r < n; ++r) {
            if (z[l][r] == ans) ++cnt;
            else if (z[l][r] > ans) {
                ans = z[l][r];
                cnt = 1;
            }
            if (a[l] > a[r]) ++rev;
    }
}

int main(){
    init();
    work();
    cout<< rev - ans << ' '<< cnt<< endl;
}


#include<cmath>
#include<queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include<algorithm>
using namespace std;
const int MAXN = 5009;
int cnt[MAXN*MAXN], sum[MAXN][MAXN], a[MAXN];
int main() {
    int n, i, j, mi, ans, x, y;
    while(scanf("%d", &n) != EOF) {
        memset(cnt, 0, sizeof(cnt));
        memset(sum, 0, sizeof(sum));
        for(i=1; i<=n; ++i) {
            scanf("%d", a+i);
            ++a[i];
            ++sum[i][a[i]];
        }
        for(i=1; i<=n; ++i) {
            for(j=1; j<=n; ++j){
                sum[i][j] = sum[i-1][j] + (a[i]<=j);
            }
        }
        int rev = 0;
        mi = (n-1)*n/2;
        for(i=1; i<=n; ++i) {
            for(j=i+1; j<=n; ++j) rev += a[i]>a[j];
        }
        for(i=1; i<=n; ++i) {
            x=a[i];
            for(j=i+1; j<=n; ++j) {
                y = a[j];
                int t = rev;
                t -= sum[j-1][x-1]-sum[i][x-1];//<x
                t += sum[j-1][n]-sum[j-1][x] - (sum[i][n]-sum[i][x]);//>x
                t += sum[j-1][y-1] -sum[i][y-1];//<y;
                t -= sum[j-1][n]-sum[j-1][y] - (sum[i][n]-sum[i][y]);//>y
                t += x<y ? 1 : -1;
                ++cnt[t];
            }
        }

        for(i=0; ; ++i) {
            if(cnt[i]) {
                printf("%d %d\n", i, cnt[i]); break;
            }
        }
    }
    return 0;
}


//ITNOG
#include <bits/stdc++.h>

using namespace std;
//#define int long long
const int maxN = 5000 + 5;
const int lim = 1000*1000*1000;
const int inf = 1000*1000*1000 + 5;
int a[maxN];
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i ++)
	  cin >> a[i], ans += abs(a[i] - i);
    int answer = ans, cnt = 0;
    for(int i = 0; i < n; i ++)
	  for(int j = i + 1; j < n; j ++)
	  {
		int tmp = ans; tmp -= abs(a[i] - i) + abs(a[j] - j);
		tmp += abs(a[j] - i) + abs(a[i] - j);
		if(answer > tmp) answer = tmp, cnt = 1;
		else if(answer == tmp) cnt ++;
	  }
    cout << answer / 2 << ' ' << cnt << endl;

    return 0;

}


//ITNOG
#include <bits/stdc++.h>

using namespace std;
//#define int long long
const int maxN = 5000 + 5;
const int lim = 1000*1000*1000;
const int inf = 1000*1000*1000 + 5;
int a[maxN];
vector<int> v[maxN];
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    for(int i = 0; i < n; i ++)
    {
	  cin >> a[i];
	  for(int j = i; j < n; j ++)
		v[j].push_back(a[i]);
    }
    for(int i = 0; i < n; i ++)
	  sort(v[i].begin(), v[i].end());

    int ans = 0;
    for(int i = 0; i < n; i ++)
	  ans += v[i].size() - 1 - (lower_bound(v[i].begin(), v[i].end(), a[i]) - v[i].begin());

    int cnt = 0;
    int answer = inf;
    for(int i = 0; i < n; i ++)
	  for(int j = i + 1; j < n; j ++)
	  {
		if(a[i] < a[j]) continue;

		int tmp = ans;
		tmp -= v[i].size() - 1 - 2 * (lower_bound(v[i].begin(), v[i].end(), a[i]) - v[i].begin());
		tmp -= v[j].size() - 1 - 2 * (lower_bound(v[j].begin(), v[j].end(), a[j]) - v[j].begin());

		tmp += v[i].size() - 2 * (lower_bound(v[i].begin(), v[i].end(), a[j]) - v[i].begin());
		tmp += v[j].size() - 2 * (lower_bound(v[j].begin(), v[j].end(), a[i]) - v[j].begin());
		if(a[i] > a[j]) tmp --;
		else tmp ++;
		if(tmp < answer) answer = tmp, cnt = 1;
		else if(tmp == answer) cnt ++;

	  }
    cout << answer << ' ' << cnt << endl;
    return 0;

}


//ITNOG
#include <bits/stdc++.h>

using namespace std;
//#define int long long
const int maxN = 5000 + 5;
const int lim = 1000*1000*1000;
const int inf = 1000*1000*1000 + 5;
int a[maxN];
vector<int> v[maxN];
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    for(int i = 0; i < n; i ++)
    {
	  cin >> a[i];
	  for(int j = i; j < n; j ++)
		v[j].push_back(a[i]);
    }
    for(int i = 0; i < n; i ++)
	  sort(v[i].begin(), v[i].end());

    int ans = 0;
    for(int i = 0; i < n; i ++)
	  ans += v[i].size() - 1 - (lower_bound(v[i].begin(), v[i].end(), a[i]) - v[i].begin());

    int cnt = 0;
    int answer = inf;
    for(int i = 0; i < n; i ++)
	  for(int j = i + 1; j < n; j ++)
	  {
		int tmp = ans;
		tmp -= v[i].size() - 1 - 2 * (lower_bound(v[i].begin(), v[i].end(), a[i]) - v[i].begin());
		tmp -= v[j].size() - 1 - 2 * (lower_bound(v[j].begin(), v[j].end(), a[j]) - v[j].begin());

		tmp += v[i].size() - 2 * (lower_bound(v[i].begin(), v[i].end(), a[j]) - v[i].begin());
		tmp += v[j].size() - 2 * (lower_bound(v[j].begin(), v[j].end(), a[i]) - v[j].begin());
		if(a[i] > a[j]) tmp --;
		else tmp ++;
		if(tmp < answer) answer = tmp, cnt = 1;
		else if(tmp == answer) cnt ++;

	  }
    cout << answer << ' ' << cnt << endl;
    return 0;

}


//ITNOG
#include <bits/stdc++.h>

using namespace std;
//#define int long long
const int maxN = 5000 + 5;
const int lim = 1000*1000*1000;
const int inf = 1000*1000*1000 + 5;
int a[maxN];
vector<int> v[maxN];

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

    v[0].push_back(a[0]);

    for(int i = 1; i < n; i ++)
    {
	  int fl = 1;
	  for(int j = 0; j < v[i - 1].size(); j ++)
	  {
		if(v[i - 1][j] < a[i])
		    v[i].push_back(v[i - 1][j]);
		else
		{
		    if(fl) v[i].push_back(a[i]), fl = 0;
		    v[i].push_back(v[i - 1][j]);
		}
	  }
	  if(fl) v[i].push_back(a[i]);
    }

    int ans = 0;
    for(int i = 0; i < n; i ++)
	  ans += v[i].size() - 1 - (lower_bound(v[i].begin(), v[i].end(), a[i]) - v[i].begin());

    int cnt = 0;
    int answer = inf;
    for(int i = 0; i < n; i ++)
	  for(int j = i + 1; j < n; j ++)
	  {
		if(a[i] < a[j]) continue;

		int tmp = ans;
		tmp -= v[i].size() - 1 - 2 * (lower_bound(v[i].begin(), v[i].end(), a[i]) - v[i].begin());
		tmp -= v[j].size() - 1 - 2 * (lower_bound(v[j].begin(), v[j].end(), a[j]) - v[j].begin());

		tmp += v[i].size() - 2 * (lower_bound(v[i].begin(), v[i].end(), a[j]) - v[i].begin());
		tmp += v[j].size() - 2 * (lower_bound(v[j].begin(), v[j].end(), a[i]) - v[j].begin());
		if(a[i] > a[j]) tmp --;
		else tmp ++;
		if(tmp < answer) answer = tmp, cnt = 1;
		else if(tmp == answer) cnt ++;

	  }
    cout << answer << ' ' << cnt << endl;
    return 0;

}


#include<cstdio>
#include<climits>
#include<algorithm>

int n, a[1 << 13], cnt[1 << 13][1 << 13];

int query(int l, int r, int minv, int maxv) {
    minv++, maxv--;
    if (minv >= n || maxv < 0) {
        return 0;
    }
    int ans = cnt[r][maxv] - cnt[r][minv - 1];
    if (l) {
        ans -= (cnt[l - 1][maxv] - cnt[l - 1][minv - 1]);
    }
    return ans;
}

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

int main() {
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; ++i) {
            std::fill(cnt[i], cnt[i] + n, 0);
        }
        for (int i = 0; i < n; ++i) {
            scanf("%d", &a[i]);
            for (int j = i; j < n; ++j) {
                cnt[j][a[i]]++;
            }
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cnt[i][j] += j ? cnt[i][j - 1] : 0;
            }
        }

        int howmuch = count(), ans1 = INT_MAX, ans2 = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (a[i] > a[j]) {
                    int ans = howmuch + query(i, j, a[i], n)
                            - query(i, j, a[j], a[i]) - query(i, j, a[j], n);
                    if (ans < ans1) {
                        ans1 = ans, ans2 = 1;
                    } else if (ans == ans1)
                        ans2++;
                }
            }
        }

        printf("%d %d\n", ans1, ans2);
    }
    return 0;
}


#include<cstdio>
#include<climits>
#include<algorithm>

int n, a[5000], cnt[5000][5000];

int query(int l, int r, int minv, int maxv) {
    minv++, maxv--;
    if (minv >= n || maxv < 0) {
        return 0;
    }
    int ans = cnt[r][maxv] - cnt[r][minv - 1];
    if (l) {
        ans -= (cnt[l - 1][maxv] - cnt[l - 1][minv - 1]);
    }
    return ans;
}

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

int main() {
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; ++i) {
            std::fill(cnt[i], cnt[i] + n, 0);
        }
        for (int i = 0; i < n; ++i) {
            scanf("%d", &a[i]);
            for (int j = i; j < n; ++j) {
                cnt[j][a[i]]++;
            }
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cnt[i][j] += j ? cnt[i][j - 1] : 0;
            }
        }

        int howmuch = count(), ans1 = INT_MAX, ans2 = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (a[i] > a[j]) {
                    int ans = howmuch + query(i, j, a[i], n)
                            - query(i, j, a[j], a[i]) - query(i, j, a[j], n);
                    if (ans < ans1) {
                        ans1 = ans, ans2 = 1;
                    } else if (ans == ans1)
                        ans2++;
                }
            }
        }

        printf("%d %d\n", ans1, ans2);
    }
    return 0;
}


#ifndef MY
#define NDEBUG // only use assert locally
#endif

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <sstream>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

#define input_file(s) freopen(s, "r", stdin)
#define output_file(s) freopen(s, "w", stdout)

#define TASK_FILE_NAME ""
//#define USE_TXT_EXT_FILES // input.txt, output.txt
#define USE_STD_STREAMS // stdin, stdout - codeforces

#if defined(MY) && !defined(USE_STD_STREAMS)
#define USE_STD_STREAMS
#endif

typedef signed short int int16;
typedef unsigned short int uint16;
typedef unsigned int uint;
typedef signed long long int int64;
typedef unsigned long long int uint64;
typedef pair<int, int> ipair;

const double PI = 3.14159265358979323846;
const double SQRT2 = 1.41421356237;
const double EPS = 1e-9;

const float SQRT2F = (float)SQRT2;

const int INF = 1e9;
const int64 INF64 = 1e18;

template<class T>
T sqr(const T &x) { return x * x; }

template<class T>
T min(const T &a, const T &b, const T &c) { return min(min(a, b), c); }

template<class T>
T max(const T &a, const T &b, const T &c) { return max(max(a, b), c); }

inline void yesno(bool y) { cout << (y? "YES\n" : "NO\n"); }
inline void yes_stop(bool y) { if (y) { yesno(1); exit(0); } }
inline void no_stop(bool y) { if (!y) { yesno(0); exit(0); } }

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

// !GLOB

int n, a[5100], invers = 0;
int gt[5100][5100]; // gt[x][n] = count of elems on [0, n] that >= x
//map<int, int> c;

int main() {
    #ifndef USE_STD_STREAMS
    #ifdef USE_TXT_EXT_FILES
    input_file("input.txt");
    output_file("output.txt");
    #else
    input_file(TASK_FILE_NAME".in")
    output_file(TASK_FILE_NAME".out");
    #endif
    #endif

    //input_file("in");

    ios_base::sync_with_stdio(0);

    // !MAIN

    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 < n; ++j) {
            if (a[i] > a[j]) {
                ++invers;
            }
        }
        //cerr << i << ": " << inv[i] << endl;
    }

    //cerr << "invers: " << invers << endl;

    //cerr << "gt:\n";

    for (int x = 0; x < n; ++x) {
        gt[x][0] = a[0] > x;
        //cerr << gt[x][0];
        for (int i = 1; i < n; ++i) {
            gt[x][i] = gt[x][i - 1] + (a[i] > x);
            //cerr << " " << gt[x][i];
        }
        //cerr << endl;
    }
    //cerr << endl;

    int ans = INF, ans_c;

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int A = a[i], B = a[j];
            if (A < B) continue;
            int loc = invers + 2 * ((gt[A][j] - gt[A][i]) - (gt[B][j] - gt[B][i])) - 1;
            if (loc < ans) {
                ans = loc;
                ans_c = 1;
            } else if (loc == ans) {
                ++ans_c;
            }
        }
    }

    //cerr << "ANS:\n";

    cout << ans << " " << ans_c << endl;

    return 0;
}


#ifndef MY
#define NDEBUG // only use assert locally
#endif

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <sstream>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

#define input_file(s) freopen(s, "r", stdin)
#define output_file(s) freopen(s, "w", stdout)

#define TASK_FILE_NAME ""
//#define USE_TXT_EXT_FILES // input.txt, output.txt
#define USE_STD_STREAMS // stdin, stdout - codeforces

#if defined(MY) && !defined(USE_STD_STREAMS)
#define USE_STD_STREAMS
#endif

typedef signed short int int16;
typedef unsigned short int uint16;
typedef unsigned int uint;
typedef signed long long int int64;
typedef unsigned long long int uint64;
typedef pair<int, int> ipair;

const double PI = 3.14159265358979323846;
const double SQRT2 = 1.41421356237;
const double EPS = 1e-9;

const float SQRT2F = (float)SQRT2;

const int INF = 1e9;
const int64 INF64 = 1e18;

template<class T>
T sqr(const T &x) { return x * x; }

template<class T>
T min(const T &a, const T &b, const T &c) { return min(min(a, b), c); }

template<class T>
T max(const T &a, const T &b, const T &c) { return max(max(a, b), c); }

inline void yesno(bool y) { cout << (y? "YES\n" : "NO\n"); }
inline void yes_stop(bool y) { if (y) { yesno(1); exit(0); } }
inline void no_stop(bool y) { if (!y) { yesno(0); exit(0); } }

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }

// !GLOB

int n, a[5100], invers = 0, inv[5100] = {};
int gt[5100][5100], lt[5100][5100]; // gt[x][n] = count of elems on [0, n] that >= x
map<int, int> c;

int main() {
    #ifndef USE_STD_STREAMS
    #ifdef USE_TXT_EXT_FILES
    input_file("input.txt");
    output_file("output.txt");
    #else
    input_file(TASK_FILE_NAME".in")
    output_file(TASK_FILE_NAME".out");
    #endif
    #endif

    //input_file("in");

    ios_base::sync_with_stdio(0);

    // !MAIN

    cin >> n;

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

    //cerr << "indexed invers:\n";

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i] > a[j]) {
                ++invers;
                ++inv[i];
            }
        }
        //cerr << i << ": " << inv[i] << endl;
    }

    //cerr << "invers: " << invers << endl;

    //cerr << "gt:\n";

    for (int x = 0; x < n; ++x) {
        gt[x][0] = a[0] > x;
        lt[x][0] = a[0] < x;
        //cerr << gt[x][0];
        for (int i = 1; i < n; ++i) {
            gt[x][i] = gt[x][i - 1] + (a[i] > x);
            lt[x][i] = lt[x][i - 1] + (a[i] < x);
            //cerr << " " << gt[x][i];
        }
        //cerr << endl;
    }
    //cerr << endl;

    int ans = INF;

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            //swap(a[i], a[j]);
            int A = a[i], B = a[j];
            if (A < B) continue;
            int loc = invers - 1;
            if (i + 1 != j) {
                loc += (gt[A][j-1] - gt[A][i+1]) - (gt[B][j-1] - gt[B][i+1])
                     - (lt[A][j-1] - lt[A][i+1]) + (lt[B][j-1] - lt[B][i+1]);
            }
            //cerr << loc << " " << i << " " << j << endl;
            ++c[loc];
            ans = min(loc, ans);
            //swap(a[i], a[j]);
        }
    }

    //cerr << "ANS:\n";

    cout << ans << " " << c[ans] << endl;

    return 0;
}


#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef pair<int, int> pii;

#define FOR(i, x, y) for(ll i=x; i<=y; i++)
#define FORD(i, x, y) for (ll i = x; i >= y; --i)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REPD(i, n) for(ll i = n - 1; i >= 0; --i)

#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define SZ(c) (int)(c).size()

#define CLEAR(x) memset(x,0,sizeof x)
#define FILL(x, v) memset(x,v,sizeof x)
#define COPY(from, to) memcpy(to, from, sizeof to)

#define pb push_back
#define mp make_pair
#define X first
#define Y second

const double eps = 1.0e-11;
const double pi = acos(-1.0);
const int N = 5050;
int a[N], pref[N];

class fenwick {
  vector<int> tree_;
public:
  explicit fenwick(int size) : tree_(size) {}
  void add(int x, int i) {
    for (; x < tree_.size(); x |= (x + 1)) { tree_[x] += i; }
  }
  int sum(int x) {
    int res = 0;
    for (; x >= 0; x = (x & (x + 1)) - 1) { res += tree_[x]; }
    return res;
  }
};

int main() {
  int n, total = 0;
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    REP(j, i) total += (a[i] < a[j]);
    pref[i] = total;
  }

  int mn = N * N, num = 0;
  REP(i, n) {
    fenwick f(n), f1(n);
    int x = a[i], cnt = 0;
    REP(j, i) f.add(a[j], 1), f1.add(a[j], 1);
    REP(j, i) {
      int y = a[j];
      f1.add(a[j], - 1);
      int mx = i - j - 1 - f1.sum(x);
      int my = i - j - 1 - f1.sum(y);
      int curr = total - pref[i] +
        (j ? pref[j - 1] : 0) +
        cnt +
        (i - f.sum(a[j])) +
        (pref[i - 1] - pref[j] + my - mx);
      if (mn > curr) {
        mn = curr, num = 1;
      } else if (mn == curr) {
        ++num;
      }
      cnt += (a[j] > x);
    }
  }
  cout << mn << " " << num << endl;
    return 0;
}


#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cfloat>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;

#define sz(c) int((c).size())
#define all(c) (c).begin(), (c).end()
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define FORD(i,a,b) for (int i = int(b)-1; i >= (a); i--)
#define FORIT(i,c) for(__typeof__((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define mp make_pair
#define pb push_back
#define has(c,i) ((c).find(i) != (c).end())
#define DBG(...) { if(1) fprintf(stderr, __VA_ARGS__); }
#define DBGDO(X) { if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; }

const int maxN = 5 * 1024;
int N, K;

int arr[maxN];
int smaller[maxN][maxN]; // value, pos

int main() {
	cin >> N;
	FOR(i,0,N) cin >> arr[i];

	FOR(i,0,N) {
		int v = arr[i];
		smaller[v][i] = 0;
		FORD(j,0,i) {
			smaller[v][j] = smaller[v][j+1];
			if (arr[j] < arr[i]) smaller[v][j]++;
		}
		FOR(j,i+1,N) {
			smaller[v][j] = smaller[v][j-1];
			if (arr[j] < arr[i]) smaller[v][j]++;
		}
	}
	int inver = 0;
	FOR(i,0,N) {
		int v = arr[i];
		inver += i - smaller[v][0];
	}

	int res = inver;
	int cnt = 0;
	FOR(i,0,N) FOR(j,i+1,N) {
		int tmp = inver + ((arr[i] < arr[j]) ? 1 : -1);
		tmp -= 2 * smaller[arr[i]][j-1];
		tmp += 2 * smaller[arr[j]][i+1];

		if (tmp < res) {
			res = tmp;
			cnt = 0;
		}
		if (tmp == res) cnt++;
	}

	cout << res << " " << cnt << endl;
}


#include<iostream>
#include<vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  for(int i=0;i<n;++i)
    cin >> t[i];

  vector<vector<int> > d(n, vector<int>(n,0));
  for(int i=1;i<n;++i)
    for(int j=0;j<n;++j)
      d[i][j]=d[i-1][j]+((t[i-1]>j)?1:0);

  vector<vector<int> > e(n, vector<int>(n,0));
  for(int i=n-2;i>=0;--i)
    for(int j=0;j<n;++j)
      e[i][j]=e[i+1][j]+((t[i+1]<j)?1:0);

  int old=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<i;j++)
      if(t[i]<t[j])
	old++;

  int res=old;
  int cnt=0;
  for(int i=0;i<n;++i)
    for(int j=i+1;j<n;++j){
      int nres = old-d[i][t[i]]+d[i][t[j]]-e[i][t[i]]+e[i][t[j]]
	-d[j][t[j]]+d[j][t[i]]-e[j][t[j]]+e[j][t[i]]+1;

      // cerr << nres << ' ' << i << ' ' << j << endl;

      if(nres<res){
	res=nres;
	cnt=1;
      }
      else if(nres==res)
	cnt++;
    }

  cout << res << ' ' << cnt << '\n';

}


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

using namespace std;

#pragma comment(linker,"/STACK:16777216")
#pragma warning(disable:4786)

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define myabs(a) ((a)<0?(-(a)):(a))
#define pi acos(-1.0)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define eps 1e-9
#define root 1
#define lft 2*idx
#define rgt 2*idx+1
#define cllft lft,st,mid,s,e
#define clrgt rgt,mid+1,ed,s,e
#define inf (1<<29)
#define i64 long long
#define MX 5005

typedef pair<int,int> pii;

int v[MX][MX],a[MX];

int main(){
	//freopen("in.txt","r",stdin);
	int i,j,n,cnt,res,mx,x,y,tmp;
	while(cin>>n){
	    for(i=1;i<=n;i++)cin>>a[i];
	    CLR(v);
	    res=0;
	    for(i=1;i<=n;i++){
	        for(j=1;j<=n;j++){
	            v[i][j]=v[i][j-1];
	            if(a[j]>a[i])v[i][j]++;
	            //cout<<v[i][j]<<" ";
	        }
	        res+=v[i][i];
	        //cout<<endl;
	    }
	    cnt=mx=0;

	    for(i=1;i<=n;i++){
	        for(j=1;j<i;j++){
	            x=v[i][i]-v[i][j-1];
	            y=(i-j)-x;

	            tmp=x-y;

	            x=v[j][i]-v[j][j];
	            y=(i-j)-x;

	            tmp+=(y-x);

	            if(a[i]<a[j])tmp--;

	            if(tmp>mx){
	                mx=tmp;
	                cnt=1;
	                //cout<<mx<<" "<<i-1<<" "<<j-1<<endl;
	            }
	            else if(tmp==mx){
	                cnt++;
	                //cout<<mx<<" "<<i-1<<" "<<j-1<<endl;
	            }
	        }
	    }
	    cout<<res-mx<<" "<<cnt<<endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <complex>
#include <limits>
#include <list>
#include <stack>
#include <numeric>
#include <queue>
#include <algorithm>
#include <functional>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <map>
#include <list>
#include <math.h>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <vector>
#include <sstream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }

    vector<vector<int> > l(n, vector<int>(n + 1, 0));
    vector<vector<int> > g(n, vector<int>(n + 1, 0));
    int total_swaps = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= n; ++j) {
            l[i][j] = l[i][j-1] + (p[j-1] < p[i]);
            g[i][j] = g[i][j-1] + (p[j-1] > p[i]);
            if ((i < j-1) && p[j-1] < p[i]) ++total_swaps;
        }
    }

    int mn = numeric_limits<int>::max();
    int count = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int swaps = total_swaps - (l[i][j + 1] - l[i][i+1]) + (g[i][j + 1] - g[i][i+1]) + (l[j][j + 1] - l[j][i + 1]) - (g[j][j + 1] - g[j][i + 1]);
            if (swaps < mn) {
                mn = swaps;
                count = 1;
            }
            else if (swaps == mn) ++count;
        }
    }

    cout << mn << " " << count << endl;
}


/*
 * This is my code,
 * my code is amazing...
 */

//iostream is too mainstream
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//clibraries
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
//defines
#define ll int
#define lld long double
#define pll pair<ll,ll>
#define pld pair<lld,lld>
#define vll vector<ll>
#define vvll vector<vll>
#define INF 1000000000000000047
const char en='\n';
#define debug(x){cerr<<x<<en;}
#define prime 47
#define lprime 1000000000000000009
#define lldmin LDBL_MIN
using namespace std;
vector<vll>V,M;
vll C;

int main(){
int n;
cin>>n;
V.resize(n+47,vll(n+47,0));
M.resize(n+47,vll(n+47,0));
C.resize(n+47,0);

for(int i=1; i<=n; i++)
    cin>>C[i];

for(int i=1; i<=n; i++){

    ll pm=0, pv=0;

    for(int j=1; j<=n; j++){
    if(C[j]>C[i])pv++;
    if(C[j]<C[i])pm++;
    V[i][j]=pv;
    M[i][j]=pm;

    }
}

/*
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++)
cout<<V[i][j]<<" ";
cout<<endl;
}
cout<<endl;
for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++)
        cout<<M[i][j]<<" ";
    cout<<endl;
}
cout<<endl;
*/
ll suc=0;
for(int i=2; i<=n; i++)
suc+=V[i][i-1];

ll ma=0;
for(int i=1; i<=n; i++){
for(int j=i+1; j<=n; j++){
ll sum=V[i][i]-V[i][j]+M[i][j]-M[i][i];
//if(V[j]>V[i])sum++;
//else sum--;
sum+=V[j][j]-V[j][i]+M[j][i]-M[j][j];
ma=max(ma,sum);
//cout<<i<<" "<<j<<" "<<sum<<endl;

}
}

ll pocet=0;
for(int i=1; i<=n; i++){
    for(int j=i+1; j<=n; j++){
        ll sum=V[i][i]-V[i][j]+M[i][j]-M[i][i];
        sum+=V[j][j]-V[j][i]+M[j][i]-M[j][j];
    if(sum==ma)pocet++;
    }
       }

cout<<suc-ma<<" "<<pocet<<endl;

}


/*
 * This is my code,
 * my code is amazing...
 */

//iostream is too mainstream
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<vector>
//clibraries
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
//defines
#define ll long long
#define lld long double
#define pll pair<ll,ll>
#define pld pair<lld,lld>
#define vll vector<ll>
#define vvll vector<vll>
#define INF 1000000000000000047
const char en='\n';
#define debug(x){cerr<<x<<en;}
#define prime 47
#define lprime 1000000000000000009
#define lldmin LDBL_MIN
using namespace std;
vector<vll>V,M;
vll C;

int main(){
int n;
cin>>n;
V.resize(n+47,vll(n+47,0));
M.resize(n+47,vll(n+47,0));
C.resize(n+47,0);

for(int i=1; i<=n; i++)
    cin>>C[i];

for(int i=1; i<=n; i++){

    ll pm=0, pv=0;

    for(int j=1; j<=n; j++){
    if(C[j]>C[i])pv++;
    if(C[j]<C[i])pm++;
    V[i][j]=pv;
    M[i][j]=pm;

    }
}

/*
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++)
cout<<V[i][j]<<" ";
cout<<endl;
}
cout<<endl;
for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++)
        cout<<M[i][j]<<" ";
    cout<<endl;
}
cout<<endl;
*/
ll suc=0;
for(int i=2; i<=n; i++)
suc+=V[i][i-1];

ll ma=0;
for(int i=1; i<=n; i++){
for(int j=i+1; j<=n; j++){
ll sum=V[i][i]-V[i][j]+M[i][j]-M[i][i];
//if(V[j]>V[i])sum++;
//else sum--;
sum+=V[j][j]-V[j][i]+M[j][i]-M[j][j];
ma=max(ma,sum);
//cout<<i<<" "<<j<<" "<<sum<<endl;

}
}

ll pocet=0;
for(int i=1; i<=n; i++){
    for(int j=i+1; j<=n; j++){
        ll sum=V[i][i]-V[i][j]+M[i][j]-M[i][i];
        sum+=V[j][j]-V[j][i]+M[j][i]-M[j][j];
    if(sum==ma)pocet++;
    }
       }

cout<<suc-ma<<" "<<pocet<<endl;

}


#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 << " = " << (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))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
struct BIT {
    int s[5005]; int n;
    void init(int n) {
        this->n=n+3;    CLR(s,0);
    }
    void add(int x,int y) {
        for(x+=3;x<=n;x+=x&-x)  s[x]+=y;
    }
    int getsum(int x) {
        int r=0;
        for(x+=3;x;x-=x&-x) r+=s[x];
        return r;
    }
}sv;
struct BITT {
    vector<int> s[5005];    int n;
    void init(int n) {
        this->n=n+3;
    }
    void add(int x,int y) {
        for(x+=3;x<=n;x+=x&-x)  s[x].push_back(y);
    }
    int get(int x,int l,int r) {
        int o=0;
        for(x+=3;x;x-=x&-x) o+=(int)(upper_bound(ALL(s[x]),r)-lower_bound(ALL(s[x]),l));
        return o;
    }
}ds;
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);
    sv.init(n); ds.init(n);
    static int A[5005];
    int s=0;
    rep(i,n) {
        scanf("%d",A+i);
        s+=sv.getsum(n)-sv.getsum(A[i]);
        sv.add(A[i],1);
        ds.add(A[i],i);
    }
    // DEBUG(s);
    int res=0,minv=(int)1e9;
    rep(i,n) {
        int a=0,b=0,c;
        sv.init(n);
        REP(j,i+1,n) {
            if(j-1>i)
                a+=A[j-1]<A[i],sv.add(A[j-1],1),b=sv.getsum(A[j]);
            c=2*(b-a)+(A[j]>A[i])-(A[i]>A[j])+s;
            // printf("swap %d %d a=%d b=%d %d\n",i,j,a,b,c);
            if(c<minv)
                minv=c,res=1;
            else if(c==minv)
                ++res;
        }
    }
    printf("%d %d\n",minv,res);
    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 << " = " << (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))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
struct BIT {
    int s[5005]; int n;
    void init(int n) {
        this->n=n+3;    CLR(s,0);
    }
    void add(int x,int y) {
        for(x+=3;x<=n;x+=x&-x)  s[x]+=y;
    }
    int getsum(int x) {
        int r=0;
        for(x+=3;x;x-=x&-x) r+=s[x];
        return r;
    }
}sv;
struct BITT {
    vector<int> s[5005];    int n;
    void init(int n) {
        this->n=n+3;
    }
    void add(int x,int y) {
        for(x+=3;x<=n;x+=x&-x)  s[x].push_back(y);
    }
    int get(int x,int l,int r) {
        int o=0;
        for(x+=3;x;x-=x&-x) o+=(int)(upper_bound(ALL(s[x]),r)-lower_bound(ALL(s[x]),l));
        return o;
    }
}ds;
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);
    sv.init(n); ds.init(n);
    static int A[5005];
    int s=0;
    rep(i,n) {
        scanf("%d",A+i);
        s+=sv.getsum(n)-sv.getsum(A[i]);
        sv.add(A[i],1);
        ds.add(A[i],i);
    }
    // DEBUG(s);
    int res=0,minv=(int)1e9;
    rep(i,n) {
        int a=0,b=0,c;
        sv.init(n);
        REP(j,i+1,n) {
            if(j-1>i)
                a+=A[j-1]<A[i],b=sv.getsum(A[j]),sv.add(A[j],1);
            c=2*(b-a)+(A[j]>A[i])-(A[i]>A[j])+s;
            // printf("swap %d %d a=%d b=%d %d\n",i,j,a,b,c);
            if(c<minv)
                minv=c,res=1;
            else if(c==minv)
                ++res;
        }
    }
    printf("%d %d\n",minv,res);
    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 << " = " << (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))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
struct BIT {
    int s[5005]; int n;
    void init(int n) {
        this->n=n+3;    CLR(s,0);
    }
    void add(int x,int y) {
        for(x+=3;x<=n;x+=x&-x)  s[x]+=y;
    }
    int getsum(int x) {
        int r=0;
        for(x+=3;x;x-=x&-x) r+=s[x];
        return r;
    }
}sv;
struct BITT {
    vector<int> s[5005];    int n;
    void init(int n) {
        this->n=n+3;
    }
    void add(int x,int y) {
        for(x+=3;x<=n;x+=x&-x)  s[x].push_back(y);
    }
    int get(int x,int l,int r) {
        int o=0;
        for(x+=3;x;x-=x&-x) o+=(int)(upper_bound(ALL(s[x]),r)-lower_bound(ALL(s[x]),l));
        return o;
    }
}ds;
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);
    sv.init(n); ds.init(n);
    static int A[5005];
    int s=0;
    rep(i,n) {
        scanf("%d",A+i);
        s+=sv.getsum(n)-sv.getsum(A[i]);
        sv.add(A[i],1);
        ds.add(A[i],i);
    }
    int res=0,minv=(int)1e9;
    rep(i,n)
    REP(j,i+1,n) {
        int c,l=i+1,r=j-1,a=0,b=0;
        if(l<=r) {
            a=A[i]?ds.get(A[i]-1,l,r):0;
            b=A[j]?ds.get(A[j]-1,l,r):0;
        }
        c=2*(b-a)+(A[j]>A[i])-(A[i]>A[j])+s;
        // printf("swap %d %d %d\n",i,j,c);
        if(c<minv)
            minv=c,res=1;
        else if(c==minv)
            ++res;
    }
    printf("%d %d\n",minv,res);
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    vector<int> C[5001];
    for(int i=0;i<n;i++){
        C[i].reserve(n);
        fill(C[i].begin(),C[i].end(),0);
    }

    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(A[j]<A[i])
                C[i][j] = C[i][j+1] + 1;
            else
                C[i][j] = C[i][j+1] - 1;
        }
        for(int j=i+1;j<n;j++){
            if(A[j]<A[i])
                C[i][j] = C[i][j-1] - 1;
            else
                C[i][j] = C[i][j-1] + 1;
        }
    }

//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            printf("%2d ",C[i][j]);
//        }
//        cout << endl;
//    }

    int m = INF,cnt;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(C[i][j] + C[j][i] + 1 < m){
                m = C[i][j] + C[j][i] + 1;
                cnt = 1;
            }else if(C[i][j] + C[j][i]  + 1 == m){
                cnt++;
            }
        }
    }

    //Count inversions
    int cntInv=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntInv++;

    cout << cntInv+m << " " << cnt << endl;

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    vector<int> C[5001];
    for(int i=0;i<n;i++){
        C[i].reserve(n);
        fill_n(C[i].begin(),n,0);
    }

    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(A[j]<A[i])
                C[i][j] = C[i][j+1] + 1;
            else
                C[i][j] = C[i][j+1] - 1;
        }
        for(int j=i+1;j<n;j++){
            if(A[j]<A[i])
                C[i][j] = C[i][j-1] - 1;
            else
                C[i][j] = C[i][j-1] + 1;
        }
    }

//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            printf("%2d ",C[i][j]);
//        }
//        cout << endl;
//    }

    int m = INF,cnt;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(C[i][j] + C[j][i] + 1 < m){
                m = C[i][j] + C[j][i] + 1;
                cnt = 1;
            }else if(C[i][j] + C[j][i]  + 1 == m){
                cnt++;
            }
        }
    }

    //Count inversions
    int cntInv=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntInv++;

    cout << cntInv+m << " " << cnt << endl;

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    vector<int> C[5001];
    for(int i=0;i<n;i++){
        C[i].reserve(n);
        fill(C[i].begin(),C[i].end(),0);
    }

    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(A[j]<A[i])
                C[i][j] = C[i][j+1] + 1;
            else
                C[i][j] = C[i][j+1] - 1;
        }
        for(int j=i+1;j<n;j++){
            if(A[j]<A[i])
                C[i][j] = C[i][j-1] - 1;
            else
                C[i][j] = C[i][j-1] + 1;
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            printf("%2d ",C[i][j]);
        }
        cout << endl;
    }

    int m = INF,cnt;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(C[i][j] + C[j][i] + 1 < m){
                m = C[i][j] + C[j][i] + 1;
                cnt = 1;
            }else if(C[i][j] + C[j][i]  + 1 == m){
                cnt++;
            }
        }
    }

    //Count inversions
    int cntInv=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntInv++;

    cout << cntInv << " " << m << endl;
    cout << cntInv+m << " " << cnt << endl;

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    vector<int> C[5001];
    for(int i=0;i<n;i++)
        C[i].reserve(n);

    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(A[j]<A[i])
                C[i][j] = C[i][j+1] + 1;
            else
                C[i][j] = C[i][j+1] - 1;
        }
        for(int j=i+1;j<n;j++){
            if(A[j]<A[i])
                C[i][j] = C[i][j-1] - 1;
            else
                C[i][j] = C[i][j-1] + 1;
        }
    }

//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            printf("%2d ",C[i][j]);
//        }
//        cout << endl;
//    }

    int m = INF,cnt;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(C[i][j] + C[j][i] + 1 < m){
                m = C[i][j] + C[j][i] + 1;
                cnt = 1;
            }else if(C[i][j] + C[j][i]  + 1 == m){
                cnt++;
            }
        }
    }

    //Count inversions
    int cntInv=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntInv++;

    cout << cntInv+m << " " << cnt << endl;

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    pair<int,int> P[5001],P1[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    for(int i=0;i<n;i++){
        P[i] = make_pair(abs(A[i]-i),i);
        P1[i] = P[i];
    }

//    for(int i=0;i<n;i++)
//        cout << P[i].first << " " << P[i].second << endl;
    sort(P,P+n);
//    for(int i=0;i<n;i++)
//        cout << P[i].first << " " << P[i].second << endl;

    int l,h=P[n-1].first,cntl=0,cnth=0,index;
    for(index=n-1;index>=0;index--)
        if(P[index].first != h)
            break;
    l=P[index].first;
    for(index=n-1;index>=0;index--)
        if(P[index].first == l)
            cntl++;
        else if(P[index].first == h)
            cnth++;

    int a,b;
    for(int i=0;i<n;i++)
        if(P1[i].first == l)
            a = P1[i].second;
        else if(P1[i].first == h)
            b = P1[i].second;

    swap(A[a],A[b]);

    int inv=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                inv++;

    cout << inv << " " << cntl*cnth << endl;

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    int nL[5001],nG[5001],cntL,cntG,maxL=0,maxG=0,maxLi,maxGi;

    for(int i=0;i<n;i++){
        cntL = 0;
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntL++;
        nL[i] = cntL;
        maxL = max(maxL,cntL);
    }

    for(int i=n-1;i>=0;i--){
        cntG = 0;
        for(int j=i-1;j>=0;j--)
            if(A[i] < A[j])
                cntG++;
        nG[i] = cntG;
        maxG = max(maxG,cntG);
    }

//    for(int i=0;i<n;i++)
//        cout << nL[i] << " ";
//    cout << endl;
//    for(int i=0;i<n;i++)
//        cout << nG[i] << " ";
//    cout << endl;

//    cout << maxL << " " << maxG << endl;

    int nmaxL=0,nmaxG=0;

    for(int i=0;i<n;i++){
        if(nL[i] == maxL)
            nmaxL++, maxLi = i;
        if(nG[i] == maxG)
            nmaxG++, maxGi = i;
    }

//    cout << nmaxL << " " << nmaxG << endl;

//    cout << maxLi << " " << maxGi << endl;

    swap(A[maxLi],A[maxGi]);

    int sum=0;

    for(int i=0;i<n;i++){
        cntL = 0;
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntL++, maxLi = i;
        sum += cntL;
    }

    cout << sum << " " << nmaxL*nmaxG << endl;

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    vector<int> C[5001];
    for(int i=0;i<n;i++){
        C[i].reserve(n);
        fill_n(C[i].begin(),n,0);
    }

    //C[i][j] is the change in inversion when we swap A[i] and A[j]
    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(A[j]<A[i])
                C[i][j] = C[i][j+1] + 1;
            else
                C[i][j] = C[i][j+1] - 1;
        }
        for(int j=i+1;j<n;j++){
            if(A[j]<A[i])
                C[i][j] = C[i][j-1] - 1;
            else
                C[i][j] = C[i][j-1] + 1;
        }
    }

//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            printf("%2d ",C[i][j]);
//        }
//        cout << endl;
//    }

    //Try all pairs (i,j) to see which pairs minimize the inversion change
    //and also count them
    int m = INF,cnt;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(C[i][j] + C[j][i] + 1 < m){// +1 because the inversion of the 2 elements (i,j) is counted twice
                m = C[i][j] + C[j][i] + 1;
                cnt = 1;
            }else if(C[i][j] + C[j][i]  + 1 == m){
                cnt++;
            }
        }
    }

    //Count inversions
    int cntInv=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntInv++;

    cout << cntInv+m << " " << cnt << endl;

    return 0;
}


#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iterator>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define INF 1000000000
#define MOD 1000000007

int main()
{
    int n,A[5001];
    cin >> n;

    for(int i=0;i<n;i++)
        cin >> A[i];

    vector<int> C[5001];
    for(int i=0;i<n;i++){
        C[i].reserve(n);
        fill(C[i].begin(),C[i].end(),0);
    }

    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(A[j]<A[i])
                C[i][j] = C[i][j+1] + 1;
            else
                C[i][j] = C[i][j+1] - 1;
        }
        for(int j=i+1;j<n;j++){
            if(A[j]<A[i])
                C[i][j] = C[i][j-1] - 1;
            else
                C[i][j] = C[i][j-1] + 1;
        }
    }

//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            printf("%2d ",C[i][j]);
//        }
//        cout << endl;
//    }

    int m = INF,cnt;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(C[i][j] + C[j][i] + 1 < m){
                m = C[i][j] + C[j][i] + 1;
                cnt = 1;
            }else if(C[i][j] + C[j][i]  + 1 == m){
                cnt++;
            }
        }
    }

    //Count inversions
    int cntInv=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(A[i] > A[j])
                cntInv++;

    cout << cntInv << " " << m << endl;
    cout << cntInv+m << " " << cnt << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>

#define FOR(i, a, b) for(int i = a; i < (int)(b) + 1; ++i)
#define FORD(i, a, b) for(int i = a; i >= (int)(b); --i)

#define next(type, i) type i; cin >> i;
#define nextVector(type, v, size) vector<type> v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

using namespace std;

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

    next(int, n)
    nextVector(int, v, n)

    vector<int> index(n);
    FOR (i, 0, n - 1) index[v[i]] = i;

    int smallerThan[n][n];
    FOR (i, 0 , n - 1) smallerThan[0][i] = 0;
    FOR (i, 1, n - 1) FOR (a, 0, n - 1) {
    	smallerThan[i][a] = smallerThan[i - 1][a] + (v[i - 1] < a ? 1 : 0);
    }

    int curRes = 0;
    FOR (i, 0, n - 1) FOR (j, i + 1, n - 1) if (v[i] > v[j]) curRes++;

    int best = 0;
    int bestCount = 0;
    FOR (a, 0, n) FOR (b, 0, a - 1) {
    	if (index[b] < index[a]) continue;
    	int i1 = index[a] + 1;
    	int i2 = index[b];

    	int res = 2*( (smallerThan[i2][a] - smallerThan[i2][b + 1]) -
    				  (smallerThan[i1][a] - smallerThan[i1][b + 1])) + 1;
    	if (res > best) {

    		best = res;
    		bestCount = 1;
    	} else if (res == best) bestCount++;
    }

    cout << curRes - best << ' ' << bestCount;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>

#define FOR(i, a, b) for(int i = a; i < (int)(b) + 1; ++i)
#define FORD(i, a, b) for(int i = a; i >= (int)(b); --i)

#define next(type, i) type i; cin >> i;
#define nextVector(type, v, size) vector<type> v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

using namespace std;

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

    next(int, n)
    nextVector(int, v, n)

    vector<int> index(n);
    FOR (i, 0, n - 1) index[v[i]] = i;

    int smallerThan[n][n];
    FOR (i, 0 , n - 1) smallerThan[0][i] = 0;
    FOR (i, 1, n - 1) FOR (a, 0, n - 1) {
    	smallerThan[i][a] = smallerThan[i - 1][a] + (v[i - 1] < a ? 1 : 0);
    }

    int curRes = 0;
    FOR (i, 0, n - 1) FOR (j, i + 1, n - 1) if (v[i] > v[j]) curRes++;

    int best = 0;
    int bestCount = 0;
    FOR (a, 0, n - 1) FOR (b, 0, a - 1) {
    	if (index[b] < index[a]) continue;
    	int i1 = index[a] + 1;
    	int i2 = index[b];

    	int res = 2*( (smallerThan[i2][a] - smallerThan[i2][b + 1]) -
    				  (smallerThan[i1][a] - smallerThan[i1][b + 1])) + 1;
    	if (res > best) {

    		best = res;
    		bestCount = 1;
    	} else if (res == best) bestCount++;
    }

    cout << curRes - best << ' ' << bestCount;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
#include <string.h>
#include <vector>

#define FOR(i, a, b) for(int i = a; i < (int)(b) + 1; ++i)
#define FORD(i, a, b) for(int i = a; i >= (int)(b); --i)

#define next(type, i) type i; cin >> i;
#define nextVector(type, v, size) vector<type> v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

using namespace std;

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

    next(int, n)
    nextVector(int, v, n)

    vector<int> index(n);
    FOR (i, 0, n - 1) index[v[i]] = i;

    int smallerThan[n][n];
    FOR (i, 0 , n - 1) smallerThan[0][i] = 0;
    FOR (i, 1, n - 1) FOR (a, 0, n - 1) {
    	smallerThan[i][a] = smallerThan[i - 1][a] + (v[i - 1] < a ? 1 : 0);
    }

    int curRes = 0;
    FOR (i, 0, n - 1) FOR (j, i + 1, n - 1) if (v[i] > v[j]) curRes++;

    int best = 0;
    int bestCount = 0;
    FOR (a, 0, n) FOR (b, 0, a - 1) {
    	if (index[b] < index[a]) continue;
    	int i1 = index[a] + 1;
    	int i2 = index[b];

    	int res = 2*( (smallerThan[i2][a] - smallerThan[i2][b + 1]) -
    				  (smallerThan[i1][a] - smallerThan[i1][b + 1])) + 1;
    	if (res > best) {

    		best = res;
    		bestCount = 1;
    	} else if (res == best) bestCount++;
    }

    cout << (curRes - best) << ' ' << bestCount;
}


// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,a[5010],s;
int sum[5010][5010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin>>n;
	rep(i,n){
		cin>>a[i];
		sum[i+1][a[i]+1] = 1;
	}
	rep(i,n+1){
		rep(j,n) sum[i][j+1] += sum[i][j];
	}
	rep(j,n+1){
		rep(i,n) sum[i+1][j] += sum[i][j];
	}
	rep(i,n)rep2(j,i+1,n)if(a[i]>a[j])s++;
	int m=-1,num=0;
	rep(i,n)rep2(j,i+1,n)if(a[i]>a[j]){
		int c = sum[j+1][a[i]+1] - sum[j+1][a[j]] - sum[i][a[i]+1] + sum[i][a[j]];
		if(c > m){
			m = c;
			num = 0;
		}
		if(c == m) num++;
	}
	cout<<s-(m-2)*2-1<<" "<<num<<endl;
}


#include <algorithm>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <string>
#include <vector>
#include <iostream>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define TRACE(x) cout << #x << " = " << (x) << endl

inline int myrand() { return ((rand()&((1<<15)-1)) << 15) ^ (rand()&((1<<15)-1)); }
typedef long long llint;

const int MAXN = 5012;

struct Loga {
  int seg[MAXN];
  Loga() { clear(); }
  void clear() { memset(seg, 0, sizeof seg); }
  void update(int x, int d) {
    for (++x; x < MAXN; x += x&-x)
      seg[x] += d;
  }
  int query(int x) {
    int sum = 0;
    for (; x; x -= x&-x)
      sum += seg[x];
    return sum;
  }
  int query(int a, int b) {
    return query(b) - query(a);
  }
} loga;

int n;
int A[MAXN];

int main(void)
{
  scanf("%d", &n);
  REP(i, n) scanf("%d", A+i);

  int invs = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i+1; j < n; ++j)
      if (A[i] > A[j])
        ++invs;

  int best = 1e9;
  int cnt = 0;

  for (int i = 0; i < n; ++i) {
    loga.clear();
    for (int j = i+1; j < n; ++j) {
      if (A[i] > A[j]) {
        int val = invs - 2*loga.query(A[j], A[i]) - 1;
        if (val < best) {
          best = val;
          cnt = 1;
        } else if (val == best) {
          ++cnt;
        }
      }
      loga.update(A[j], 1);
    }
  }

  printf("%d %d\n", best, cnt);
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

const int nmax = 5005;
int n;
int aib[2][nmax];

inline void update(const int &t,const int &pos,const int &val) {
	for (int i = pos;i <= n;i += (i & -i)) {
		aib[t][i] += val;
	}
}

inline int query(const int &t,const int &pos) {
	int ret = 0;
	for(int i = pos;i > 0;i -= (i & -i)) {
		ret += aib[t][i];
	}
	return ret;
}

int main()
{
//	freopen("test.in","r",stdin);freopen("test.out","w",stdout);
	cin.sync_with_stdio(false);cout.sync_with_stdio(false);
	cin >> n;
	vector<int> v(n);
	vector<int> swapNum(n);
	int M = 0;
	for (int i = 0;i < n;i++) {
		cin >> v[i];
		v[i]++;
		update(0,v[i],1);
		swapNum[i] = query(0,n) - query(0,v[i]);
		M += swapNum[i];
	}

//	cout << M << "\n";
	int bst = M, numPairs = 0;
	int posa = 0, posb = 0;
	memset(aib,0,sizeof(aib));
	int line = 0;
	for (int l = 2;l < n;l++) {
		memset(aib[1],0,sizeof(aib[1]));
		for(int k = 0;k < l ;k++) {
			update (1 - line,v[k],1);
			aib[line][k + 1] = 0;
		}

		aib[line][ l] = 0;
		for(int i = 0;i + l < n;i++) {
			aib[line][i + l + 1] = 0;
			update(1 - line,v[i + l],1);

			int s1 = query(1 - line,v[i] - 1);
			int s2 = query(1 - line,v[i + l] - 1);
			if (M + 2*(s2 - s1) < bst) {
				bst = M + 2*(s2 - s1);
				numPairs = 1;
				posa = i;
				posb = i + l;
			} else 	if (M + 2*(s2 - s1) == bst) {
				numPairs++;
			}
			update(1 - line,v[i],-1);
		}
	}

	swap(v[posa],v[posb]);
	int aux = M;
	M = 0;
		memset(aib[1],0,sizeof(aib[1]));
	for (int i = 0;i < n;i++) {
		update(1 - line,v[i],1);
		swapNum[i] = query(1 - line,n) - query(1 - line,v[i]);
		M += swapNum[i];
	}
	swap(v[posa],v[posb]);
	for (int i = 0;i < n - 1;i++) {
		if (aux + ((v[i] < v[i + 1]) ? 1 : -1 ) == M) {
			numPairs++;
		}
	}

	cout << M << " " << numPairs;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

const int nmax = 5005;
int n;
int aib[2][nmax];

inline void update(const int &t,const int &pos,const int &val) {
	for (int i = pos;i <= n;i += (i & -i)) {
		aib[t][i] += val;
	}
}

inline int query(const int &t,const int &pos) {
	int ret = 0;
	for(int i = pos;i > 0;i -= (i & -i)) {
		ret += aib[t][i];
	}
	return ret;
}

int main()
{
	//freopen("test.in","r",stdin);freopen("test.out","w",stdout);
	cin.sync_with_stdio(false);cout.sync_with_stdio(false);
	cin >> n;
	vector<int> v(n);
	vector<int> swapNum(n);
	int M = 0;
	for (int i = 0;i < n;i++) {
		cin >> v[i];
		v[i]++;
		update(0,v[i],1);
		swapNum[i] = query(0,n) - query(0,v[i]);
		M += swapNum[i];
	}

	int bst = M, numPairs = 0;
	int posa = 0, posb = 0;
	memset(aib,0,sizeof(aib));
	int line = 0;
	for (int l = 2;l < n;l++, line ^= 1) {
		for(int k = 0;k < l ;k++) {
			update (1 - line,v[k],1);
			aib[line][k + 1] = 0;
		}

		aib[line][ l] = 0;
		for(int i = 0;i + l < n;i++) {
			aib[line][i + l + 1] = 0;
			update(1 - line,v[i + l],1);

			int s1 = query(1 - line,v[i] - 1);
			int s2 = query(1 - line,v[i + l] - 1);
			if (M + 2*(s2 - s1) < bst) {
				bst = M + 2*(s2 - s1);
				numPairs = 1;
				posa = i;
				posb = i + l;
			} else 	if (M + 2*(s2 - s1) == bst) {
				numPairs++;
			}
			update(1 - line,v[i],-1);
		}
	}

	swap(v[posa],v[posb]);
	int aux = 0;
	for (int i = 0;i < n;i++) {
		update(1 - line,v[i],1);
		swapNum[i] = query(1 - line,n) - query(1 - line,v[i]);
		aux += swapNum[i];
	}
	swap(v[posa],v[posb]);
	for (int i = 0;i < n - 1;i++) {
		if (aux > ((v[i] < v[i + 1]) ? 1 : -1 ) + M) {
			aux = ((v[i] < v[i + 1]) ? 1 : -1 ) + M;
			numPairs = 1;
		} else if(((v[i] < v[i + 1]) ? 1 : -1 ) + M == aux) {
			numPairs++;
		}
	}
	M = aux;
	cout << M << " " << numPairs;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

const int nmax = 5005;
int n;
int aib[2][nmax];

inline void update(const int &t,const int &pos,const int &val) {
	for (int i = pos;i <= n;i += (i & -i)) {
		aib[t][i] += val;
	}
}

inline int query(const int &t,const int &pos) {
	int ret = 0;
	for(int i = pos;i > 0;i -= (i & -i)) {
		ret += aib[t][i];
	}
	return ret;
}

int main()
{
	//freopen("test.in","r",stdin);freopen("test.out","w",stdout);
	cin.sync_with_stdio(false);cout.sync_with_stdio(false);
	cin >> n;
	vector<int> v(n);
	vector<int> swapNum(n);
	int M = 0;
	for (int i = 0;i < n;i++) {
		cin >> v[i];
		v[i]++;
		update(0,v[i],1);
		swapNum[i] = query(0,n) - query(0,v[i]);
		M += swapNum[i];
	}

//	cout << M << "\n";
	int bst = nmax*nmax, numPairs = 0;
	int posa = 0, posb = 0;
	memset(aib,0,sizeof(aib));
	int line = 0;
	for (int l = 2;l < n;l++, line ^= 1) {
		for(int k = 0;k < l ;k++) {
			update (1 - line,v[k],1);
			aib[line][k + 1] = 0;
		}

		aib[line][ l] = 0;
		for(int i = 0;i + l < n;i++) {
			aib[line][i + l + 1] = 0;
			update(1 - line,v[i + l],1);

			int s1 = query(1 - line,v[i] - 1);
			int s2 = query(1 - line,v[i + l] - 1);
			if (M + 2*(s2 - s1) < bst) {
				bst = M + 2*(s2 - s1);
				numPairs = 1;
				posa = i;
				posb = i + l;
			} else 	if (M + 2*(s2 - s1) == bst) {
				numPairs++;
			}
			update(1 - line,v[i],-1);
		}
	}

	swap(v[posa],v[posb]);
	int aux = M;
	M = 0;
	for (int i = 0;i < n;i++) {
		update(1 - line,v[i],1);
		swapNum[i] = query(1 - line,n) - query(1 - line,v[i]);
		M += swapNum[i];
	}
	swap(v[posa],v[posb]);
	for (int i = 0;i < n - 1;i++) {
		if (aux + ((v[i] < v[i + 1]) ? 1 : -1 ) == M) {
			numPairs++;
		}
	}

	cout << M << " " << numPairs;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

const int nmax = 5005;
int n;
int aib[2][nmax];

inline void update(const int &t,const int &pos,const int &val) {
	for (int i = pos;i <= n;i += (i & -i)) {
		aib[t][i] += val;
	}
}

inline int query(const int &t,const int &pos) {
	int ret = 0;
	for(int i = pos;i > 0;i -= (i & -i)) {
		ret += aib[t][i];
	}
	return ret;
}

int main()
{
	//freopen("test.in","r",stdin);freopen("test.out","w",stdout);
	cin.sync_with_stdio(false);cout.sync_with_stdio(false);
	cin >> n;
	vector<int> v(n);
	vector<int> swapNum(n);
	int M = 0;
	for (int i = 0;i < n;i++) {
		cin >> v[i];
		v[i]++;
		update(0,v[i],1);
		swapNum[i] = query(0,n) - query(0,v[i]);
		M += swapNum[i];
	}

//	cout << M << "\n";
	int bst = nmax*nmax, numPairs = 0;
	int posa = 0, posb = 0;
	memset(aib,0,sizeof(aib));
	int line = 0;
	for (int l = 2;l < n;l++, line ^= 1) {
		for(int k = 0;k < l ;k++) {
			update (1 - line,v[k],1);
			aib[line][k + 1] = 0;
		}

		for(int i = 0;i + l < n;i++) {
			aib[line][i + l + 1] = 0;
			update(1 - line,v[i + l],1);

			int s1 = query(1 - line,v[i] - 1);
			int s2 = query(1 - line,v[i + l] - 1);
			if (M + -s1 + (l + 1 - s1) + s2 - (l + 1 - s2) < bst) {
				bst = M + -s1 + (l + 1 - s1) + s2 - (l + 1 - s2);
				numPairs = 1;
				posa = i;
				posb = i + l;
			} else 	if (M + -s1 + (l + 1 - s1) + s2 - (l + 1 - s2) == bst) {
				numPairs++;
			}
			update(1 - line,v[i],-1);
		}
	}

	swap(v[posa],v[posb]);
	int aux = M;
	M = 0;
	for (int i = 0;i < n;i++) {
		update(1 - line,v[i],1);
		swapNum[i] = query(1 - line,n) - query(1 - line,v[i]);
		M += swapNum[i];
	}
	swap(v[posa],v[posb]);
	for (int i = 0;i < n - 1;i++) {
		if (aux + ((v[i] < v[i + 1]) ? 1 : -1 ) == M) {
			numPairs++;
		}
	}

	cout << M << " " << numPairs;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<cstring>
#include<vector>
#include<bitset>
#include<iterator>
#include<list>
#include<map>
#include<cstdlib>
#include<ctime>
#include<utility>
using namespace std;
#define L p->ch[0]
#define R p->ch[1]
#define KeyTree root->ch[1]->ch[0]
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int maxn = 1155111;
const int INF = 1 << 30;
const int mod = 10007;
const ULL X = 123;
template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
bool g[10][10][10][10];
int d[maxn];
bool go(int n, int m) {
    if (d[0] == 1 || d[m - 1] == n)
        return false;
    for (int i = 2; i < m; ++i) {
        if (d[i - 2] + 1 == d[i - 1] && d[i - 1] + 1 == d[i])
            return false;
    }
    return true;
}
int a[5002];
int b[5002];
int c[5002], n;
int lowbit(int x) {
    return x & -x;
}
void update(int p) {
    while (p <= n) {
        c[p]++;
        p += lowbit(p);
    }

}
int query(int p) {
    int s = 0;
    while (p) {
        s += c[p];
        p -= lowbit(p);
    }
    return s;
}
int main() {
    ios::sync_with_stdio(false);
    int i, j;
    cin >> n;
    int s = 0;
    for (i = 0; i < n; ++i) {
        cin >> a[i];
        a[i]++;
    }
    for (i = 0; i < n; ++i) {
        for (j = i + 1; j < n; ++j)
            s += a[i] > a[j];
    }
    int ans = s, cnt = 0;
    for (i = 0; i < n; ++i) {
        memset(c, 0, sizeof(c));
        for (j = i + 1; j < n; ++j) {
            int x = query(n) - query(a[i]);
            int y = query(a[i] - 1);
            int tmp = s;
            tmp += x - y;

            x = query(n) - query(a[j]);
            y = query(a[j] - 1);
            tmp += y - x;

            if (a[i] > a[j])
                tmp--;
            else
                tmp++;
            if (tmp < ans) {
                ans = tmp;
                cnt = 1;
            } else if (tmp == ans) {
                ++cnt;
            }
            update(a[j]);
        }
    }
    printf("%d %d\n", ans, cnt);
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {

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

    vector<vector<int>> inversions(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = i-1; j >= 0; j--) {
            inversions[i][j] = inversions[i][j+1];
            if (a[j] > a[i]) {
                inversions[i][j]++;
            } else {
                inversions[i][j]--;
            }
        }
        for (int j = i+1; j < n; j++) {
            inversions[i][j] = inversions[i][j-1];
            if (a[j] < a[i]) {
                inversions[i][j]++;
            } else {
                inversions[i][j]--;
            }
        }
    }

    int totalInversion = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[j] < a[i]) {
                totalInversion++;
            }
        }
    }
    int maxReduction = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int r = inversions[i][j] + inversions[j][i] - 1;
            maxReduction = max(maxReduction, r);
        }
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int r = inversions[i][j] + inversions[j][i] - 1;
            if (r == maxReduction) {
                count++;
            }
        }
    }
    cout << totalInversion-maxReduction << " " << count << endl;

    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[maxn], tr[maxn], s1[maxn][maxn], s2[maxn][maxn];
inline int getsum(int x)
{
	int r = 0;
	while(x)
	{
		r += tr[x];		x -= x&-x;
	}
	return r;
}
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);
	FOR(i, 1, n)
		scanf("%d", p+i), ++p[i];
	int r1 = 0;
	FOR(i, 1, n)
	{
		r1 += getsum(n) - getsum(p[i]);
		for(int x=p[i]; x<=n; x+=x&-x)
			tr[x] += 1;
	}
	FOR(i, 1, n)
	FOR(j, 1, n)
		s1[i][j] = p[j] > i, s2[i][j] = p[j] < i;
	FOR(i, 1, n)
	FOR(j, 1, n)
		s1[i][j] += s1[i][j-1], s2[i][j] += s2[i][j-1];
	int r = (int)1e9;
	map<int, int> rd;
	FOR(i, 1, n)
	FOR(j, i+1, n)
	{
		int r2 = r1;
		r2 -= s2[p[i]][j] - s2[p[i]][i];
		r2 += s1[p[i]][j] - s1[p[i]][i];
		r2 -= s1[p[j]][j-1] - s1[p[j]][i-1];
		r2 += s2[p[j]][j-1] - s2[p[j]][i-1];
		r2 += p[i] > p[j];
		++rd[r2];		r = min(r, r2);
	}
	int rc = 0;
	map<int, int>::iterator lt = rd.begin();	rc = lt->second;
	printf("%d %d\n", r, rc);
	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[maxn], tr[maxn], s1[maxn][maxn], s2[maxn][maxn], ans[maxn][maxn];
inline int getsum(int x)
{
	int r = 0;
	while(x)
	{
		r += tr[x];		x -= x&-x;
	}
	return r;
}
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);
	FOR(i, 1, n)
		scanf("%d", p+i), ++p[i];
	int r1 = 0;
	FOR(i, 1, n)
	{
		r1 += getsum(n) - getsum(p[i]);
		for(int x=p[i]; x<=n; x+=x&-x)
			tr[x] += 1;
	}
	FOR(i, 1, n)
	FOR(j, 1, n)
		s1[i][j] = p[j] > i, s2[i][j] = p[j] < i;
	FOR(i, 1, n)
	FOR(j, 1, n)
		s1[i][j] += s1[i][j-1], s2[i][j] += s2[i][j-1];
	int r = (int)1e9;
	FOR(i, 1, n)
	FOR(j, i+1, n)
	{
		int r2 = r1;
		r2 -= s2[p[i]][j] - s2[p[i]][i];
		r2 += s1[p[i]][j] - s1[p[i]][i];
		r2 -= s1[p[j]][j-1] - s1[p[j]][i-1];
		r2 += s2[p[j]][j-1] - s2[p[j]][i-1];
		r2 += p[i] > p[j];
		ans[i][j] = r2;		r = min(r, r2);
	}
	int rc = 0;
	FOR(i, 1, n)		FOR(j, i+1, n)
		rc += ans[i][j] == r;
	printf("%d %d\n", r, rc);
	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[maxn], tr[maxn], s1[maxn][maxn], s2[maxn][maxn];
inline int getsum(int x)
{
	int r = 0;
	while(x)
	{
		r += tr[x];		x -= x&-x;
	}
	return r;
}
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);
	FOR(i, 1, n)
		scanf("%d", p+i), ++p[i];
	int r1 = 0;
	FOR(i, 1, n)
	{
		r1 += getsum(n) - getsum(p[i]);
		for(int x=p[i]; x<=n; x+=x&-x)
			tr[x] += 1;
	}
	FOR(i, 1, n)
	FOR(j, 1, n)
		s1[i][j] = p[j] > i, s2[i][j] = p[j] < i;
	FOR(i, 1, n)
	FOR(j, 1, n)
		s1[i][j] += s1[i][j-1], s2[i][j] += s2[i][j-1];
	int r = (int)1e9, big1 = -1, big2 = -1, rc = 0;
	FOR(i, 1, n)
	FOR(j, i+1, n)
	{
		int r2 = r1;
		r2 -= s2[p[i]][j] - s2[p[i]][i];
		r2 += s1[p[i]][j] - s1[p[i]][i];
		r2 -= s1[p[j]][j-1] - s1[p[j]][i-1];
		r2 += s2[p[j]][j-1] - s2[p[j]][i-1];
		r2 += p[i] > p[j];
		r = min(r, r2);
		if(big1 == -1 || r2 < big1)
			big2 = big1, big1 = r2, rc = 1;
		else if(r2 == big1)
			++rc;
		else if(big2 == -1 || r2 < big2)
			big2 = r2;
	}
	printf("%d %d\n", r, rc);
	return 0;
}