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
97
98
// {{{
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define each(...)    for (auto& __VA_ARGS__)
#define rep(i, b, e) for (int i = (b); i <= (e); i++)
#define rev(i, b, e) for (int i = (e); i >= (b); i--)
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#ifdef SPONGE
#define dbg(f, ...) fprintf(stderr, "\033[1;33m" f "\033[0m", ##__VA_ARGS__)
#else
#define dbg(...) 1
#endif
#define tC template<class

using namespace std;

tC T> using V = vector<T>;
tC T1, class T2> using P = pair<T1,T2>;
tC T, class C=greater<T>> using PQ = priority_queue<T,V<T>,C>;

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using pii = P<int,int>;
using pll = P<ll,ll>;
using pld = P<ld,ld>;
using vi = V<int>;
using vll = V<ll>;
using vld = V<ld>;
using vb = V<bool>;
using vs = V<string>;
using vpii = V<pii>;
using vpll = V<pll>;
using vpld = V<pld>;

tC T> int sz(const T& a) { return (int)a.size(); }
tC T> bool amin(T& a, T b) { return b < a ? a = b, 1 : 0; }
tC T> bool amax(T& a, T b) { return b > a ? a = b, 1 : 0; }

const size_t rseed = 4488;
// chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(rseed);
tC T> T rand(T lo, T hi) { return uniform_int_distribution<T>{lo,hi}(rnd); }

const int oo = 1e9 + 1;
const ll OO = 1e18 + 1;

namespace { void solve(); }
// }}}

int main()
{
  int t = 1;
  // scanf("%d", &t);
  rep(i, 1, t) {
    // printf("Case #%d: ", i);
    solve();
  }
}

namespace {

const int N = 305;
int n, perm[N], odl[N][N];

void solve()
{
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d", &perm[i]);

  rep(i, 1, n) rep(j, 1, n) odl[i][j] = oo;
  rep(i, 1, n) odl[i][i] = 0;

  rep(i, 1, n) rep(j, i + 1, n) {
    if (perm[i] > perm[j]) {
      odl[i][j] = 1;
      odl[j][i] = 1;
      //dbg("%d ~ %d\n", i, j);
    }
  }

  rep(k, 1, n) rep(i, 1, n) rep(j, 1, n) amin(odl[i][j], odl[i][k] + odl[k][j]);

  rep(i, 1, n) {
    int suma = 0;
    rep(j, 1, n) if (odl[i][j] < oo) suma += odl[i][j];
    printf("%d ", suma);
  }
  printf("\n");
}

}