1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


const int maxN = 64;
int t[maxN];
int N;
int res[maxN], res_cnt[maxN];


int cnt_inv(ll mask) {
    int inv = 0;
    ll taken = 0;
    while (mask) {
        int i = __builtin_ctzll(mask);
        inv += __builtin_popcount((~((1 << t[i]) - 1)) & taken);
        taken |= 1 << t[i];
        mask ^= 1 << i;
    }
    return inv;
}


int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        res[i + 1] = 1e9;
        scanf("%d", t + i);
    }

    for (ll mask = 1; mask < (1LL << N); ++mask) {
        int x = __builtin_popcountll(mask);
        int inv = cnt_inv(mask);
        if (res[x] > inv) {
            res[x] = inv;
            res_cnt[x] = 0;
        }
        res_cnt[x] += res[x] == inv;
    }

    for (int i = 1; i <= N; ++i)
        printf("%d %d\n", res[i], res_cnt[i]);
}