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
#include<bits/stdc++.h>
using namespace std;
int tab[45];
int mini[45];
int na_ile[45];
vector<int> v;
int zlicz()
{
    int pom=0;
    for(int x=0;x<v.size();x++)
        for(int y=x+1;y<v.size();y++)
            if(v[y]<v[x])
                pom++;
    return pom;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	for(int x=0;x<40;x++)
        mini[x]=1e9+7;
    int a;
    cin>>a;
    for(int x=0;x<a;x++)
        cin>>tab[x];
    int pom=(1<<a)-1;
    while(pom!=0)
    {
        int xd=pom,where=0,ile=0,dd;
        while(xd!=0)
        {
            if(xd%2==1)
                v.push_back(tab[where]);
            where++;
            ile+=xd%2;
            xd/=2;
        }
        dd=zlicz();
        if(mini[ile]==dd)
            na_ile[ile]++;
        else if(mini[ile]>dd)
        {
            mini[ile]=dd;
            na_ile[ile]=1;
        }
        pom--;
        v.resize(0);
    }
    for(int x=1;x<=a;x++)
    {
        cout<<mini[x]<<" "<<na_ile[x]<<'\n';
    }
	return 0;
}