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
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>

// just lame brutal force

int A[41];

struct Best {
    int v;
    int c;
    Best()
        : v(1000000)
        , c(0) {}
    void update(int v)
    {
        if (this->v > v) {
            this->v = v;
            c = 1;
        } else if (this->v == v) {
            ++c;
        }
    }
} BB[41];

int main() {
    std::ios_base::sync_with_stdio(0);
    int n;
    std::cin >> n;
    for (int i=0;i<n;++i) std::cin >> A[i];
    
    uint64_t M = 1ull<<n;
    for (uint64_t b=1;b<M;++b) {
        int c = 0;
        for (uint64_t i=1;i<=b;i<<=1) {
            if (b & i) {
                ++c;
            }
        }
        int z = 0;
        for (int i=0;i<n;++i) {
            if (b & (1ull<<i)) {
                for (int j=i+1;j<n;++j) {
                    if ((b & (1ull<<j)) && A[i] > A[j]) {
                        ++z;
                    }
                }
            }
        }
        BB[c].update(z);
    }
    for (int i=1;i<=n;++i) {
        std::cout << BB[i].v << " " << BB[i].c << std::endl;
    }

    return 0;
}