1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <ios>
long long a,b,c,d,e,f,l,k,p,w,n;
long long wej[4001],odl[4001][4001];
int main(){
    scanf("%lld", &n);
    for (a=1; a<=n; ++a){
        scanf("%lld", &wej[a]);
        for (b=1; b<=n; ++b)
            odl[a][b]=1<<20;
        odl[a][a]=0;
        for (b=1; b<a; ++b)
            if (wej[a]<wej[b])
                odl[a][b]=odl[b][a]=1;
    }
    for (a=1; a<=n; ++a)
        for (b=1; b<=n; ++b)
            for (c=1; c<=n; ++c)
                odl[b][c]=std::min(odl[b][c], odl[b][a]+odl[a][c]);
    for (a=1; a<=n; ++a){
        for (b=1,w=0; b<=n; ++b)
            w+=odl[a][b]<(1<<20) ? odl[a][b] : 0;
        printf("%lld ", w);
    }
}