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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//   _|                                                _|
//   _|  _|    _|    _|    _|_|    _|_|_|      _|_|_|  _|  _|      _|_|      _|_|
//   _|_|      _|    _|  _|_|_|_|  _|    _|  _|_|      _|_|      _|_|_|_|  _|_|_|_|
//   _|  _|    _|    _|  _|        _|    _|      _|_|  _|  _|    _|        _|
//   _|    _|    _|_|_|    _|_|_|  _|_|_|    _|_|_|    _|    _|    _|_|_|    _|_|_|
//                   _|            _|
//               _|_|              _|
#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>

using namespace std;

// #define DEBUG
#ifdef DEBUG
#define dassert(x) assert(x);
#define df(...) printf(__VA_ARGS__)
#else
#define dassert(x)
#define df(...)
#endif

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define ir(x, a, b) ((a) <= (x) && (x) <= (b))
#define vec vector
#define sz(x) (ll)x.size()
#define foru(i, n) for (int i = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()
#define fori(i, a, b) for (int i = (a); (i) < (n); ++(i))

typedef int64_t ll;

const int N = 100;
ll e[N][N];

int main() {
    df("debug mode\n");
#ifndef DEBUG
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
    int n;
    cin >> n;
    vec<int> a(n);
    foru (i, n) { cin >> a[i]; --a[i]; }
    vec<int> r(n);
    foru (i, n) r[a[i]] = i;
    foru (i, n) foru (j, n) e[i][j] = 1e9;
    foru (i, n) {
        e[i][i] = 0;
        foru (j, i) {
            if (a[j] > a[i]) e[i][j] = e[j][i] = 1;
        }
    }
    
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                e[i][j] = min(e[i][j], e[i][k] + e[k][j]); 
            }
        }
    }
    
    foru (i, n) {
        int s = 0;
        foru (j, n) {
            if (e[i][j] >= 1e9) continue;
            s += e[i][j];
        }
        cout << s << " ";
    }
    cout << "\n";
    
    // foru (i, n) {
    //     int b = 1e9;
    //     for (int j = a[i]+1; j < n; ++j) {
    //         b = min(b, r[j]);
    //     }
    //     if (b > i) continue;
    //     int l = 0, m = 0, r = 0;
    //     for (int x = i+1; x < b; ++x) {
    //         if (a[x] < a[i]) ++l;
    //         else if (ir(a[x], a[i], b)) ++m;
    //         else if (b > a[i]) ++r;
    //         else assert(0);
    //     }
    //     dp[i].x = dp[b].x + r + 1;
    //     dp[i].y = dp[b].y + 2*l - m + r + dp[b].x + 1;
    //     df("i: %d\n", i);
    //     df("%d %d\n", dp[i].x, dp[i].y);
    // }
    return 0;
}