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
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, v) for(auto &x: v)
#define PB push_back
#define SZ(x) ((int)x.size())
#define X first
#define Y second

using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;

constexpr int N = 5124;

int dist[N][N];

void solve() {
    int n;
    cin >> n;
    vi vec(n);
    TRAV(x, vec) cin >> x;
    FOR(i, 0, n) FOR(j, i + 1, n) dist[i][j] = dist[j][i] = (vec[i] > vec[j] ? 1 : INF);
    FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    FOR(i, 0, n) {
        long long sum = 0;
        FOR(j, 0, n) sum += (dist[i][j] != INF ? dist[i][j] : 0);
        cout << sum << " \n"[i + 1 == n];
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int tt; cin >> tt;
    // FOR(te, 0, tt) {
    //     // cout << "Case #" << te + 1 << ": ";
    //     solve();
    // }
    solve();
    return 0;
}