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
#include <bits/stdc++.h>
#define dbg(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

int n,a[41],m[41],w[41],c,l;

int main() {
	scanf("%d",&n);
	for (int i=1; i<=n; ++i) w[i]=1000000000;
	for (int i=0; i<n; ++i) {scanf("%d",&a[i]);}
	for (long long i=1; i<(1LL<<n); ++i) {
		c=0; l=0;
		for (int j=0; j<n; ++j) {
			if (i&(1LL<<j)) {
				++c;
				for (int k=j+1; k<n; ++k) {
					if (i&(1LL<<k)) {
						if (a[j]>a[k]) ++l;
					}
				}
			}
		}
		if (l<w[c]) {w[c]=l; m[c]=1;}
		else if (l==w[c]) {++m[c];}
	}
	for (int i=1; i<=n; ++i) {printf("%d %d\n",w[i],m[i]);}
	return 0;
}