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 <cstdio>
#include <cstdlib>

#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;

int read() { int n; scanf("%d", &n); return n; }

const int MAXN = 40 + 4;

int n;
int sold[MAXN];

int brute() {
	int tmp[MAXN];

	vector<int> val(n+1, 999999);
	vector<int> cnt(n+1, 0);

	for (ll mask = (1LL << n) - 1; mask > 0; --mask) {
		int pc = 0;
		for (int x=0; x<n; ++x)
			if (mask & (1LL << x))
				tmp[pc++] = x;
		int coll = 0;
		for (int i=0; i<pc; ++i) for (int j=i+1; j<pc; ++j)
			if (sold[tmp[i]] > sold[tmp[j]])
				++coll;
		if (coll < val[pc]) {
			val[pc] = coll;
			cnt[pc] = 0;
		}
		if (coll == val[pc])
			++cnt[pc];
	}

	for (int k=1; k<=n; ++k)
		printf("%d %d\n", val[k], cnt[k]);

	return 0;
}


int main() {
	n = read();
	for (int i=0; i<n; ++i) sold[i] = read();

	return brute();
}