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 <iostream>
#include <climits>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cmath>

using namespace std;

int A[40];
int B[40];
int b=0;
int n;

pair <int, long long> W[41];




void f(int i, int z) {
    if (i==n) {
        if (W[b].first<z) return;
        if (W[b].first>z) W[b]=make_pair(z, 1LL);
        else W[b].second++;
        return;
    }
    f(i+1, z);
    for (int j=0; j<b; j++) z+=(B[j]>A[i]);
    B[b++]=A[i];
    f(i+1, z);
    b--;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    W[0]=make_pair(10000, 0LL);
    for (int i=0; i<n; i++) {
        cin >> A[i];
        W[i+1]=make_pair(10000, 0LL);
    }
    f(0, 0);
    for (int i=1; i<=n; i++) {
        cout << W[i].first << " " << W[i].second << endl;
    }
    return 0;
}