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
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")

const int MAXN=27;
const int inf=1e9+2137;

int dp[(1<<MAXN)];
int v[MAXN];
int pos[MAXN];
int res[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,p,m,b;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>v[i],res[i+1]=inf;
    for(int i=1;i<(1<<n);i++)
    {
        p=-1;
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                if(p==-1)
                    p=j;
                else
                if(v[j]<v[p])
                    dp[i]++;
            }
        }
        dp[i]+=dp[i^(1<<p)];
        b=__builtin_popcount(i);
        if(dp[i]<res[b])
            res[b]=dp[i],pos[b]=0;
        if(dp[i]==res[b])
            pos[b]++;
    }
    for(int i=1;i<=n;i++)
        cout<<res[i]<<' '<<pos[i]<<'\n';
}