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
#include <bits/stdc++.h>

using namespace std;

int n;
int a[50];
int res[50], cnt[50];

void check(int i = 1, int used = 0, int inv = 0, int total = 0) {
	if(i == n + 1) {
		int c = total;
		if(res[c] == inv)
			cnt[c]++;
		else if(res[c] > inv) {
			res[c] = inv;
			cnt[c] = 1;
		}
		return ;
	}
	
	check(i + 1, used, inv, total);
	
	used ^= (1 << a[i]);
	int minv = inv;
	inv += total - __builtin_popcount(used & ((1 << a[i]) - 1));
	total++;
	
	check(i + 1, used, inv, total);
	
	used ^= (1 << a[i]);
	inv = minv;
	total--;
}

int main() {
	scanf("%d", &n);
	for(int i = 1 ; i <= n ; i++) {
		scanf("%d", &a[i]);
		a[i]--;
		res[i] = 1e8;
	}
		
	check();
	for(int k = 1 ; k <= n ; k++)
		printf("%d %d\n", res[k], cnt[k]);
		
	return 0;
}