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
56
57
58
59
#include <bits/stdc++.h>
#define booost ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fi first
#define se second
#define bp __builtin_popcount
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

const LL MOD=1e9+7;
const LL LLINF=1e18+7;

const int N=26;
map<int,int> MP[42];
const int MX= (1LL<<N);
int dp[MX];
int main()
{
    //booost;
    //freopen("C:/Users/kucha/Documents/ISIM 5. semestr/PA/tests/MS5.in","r",stdin);
    int n;
    int tab[50];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>tab[i];
    }
    for(int mask=1;mask<(1<<n);mask++)
    {
        int b=n-1;
        //cout<<mask<<" ";
        while(!((1<<b)&mask))
        {
            b--;
        }
        int cnt=0;
        int nmask=mask^(1<<b);
        for(int i=0;i<b;i++)
        {
            if((1<<i)&nmask && tab[i]>tab[b])
            {
                cnt++;
            }
        }

        dp[mask]=dp[nmask]+cnt;
        MP[bp(mask)][dp[mask]]++;
        //cout<<dp[nmask]<<" "<<dp[mask]<<'\n';
    }
    for(int i=1;i<=n;i++)
    {
        auto it=MP[i].begin();
        cout<<(it->fi)<<" "<<(it->se)<<'\n';
    }
}