for i in range(int(input())):
    n,m=map(int,input().split())
    fr,fc=n,set([i for i in range(m)])
    for i in range(n):
        r=input().split()
        h1=0
        for i in range(m):
            if r[i]=="1":
                h1=1
                if i in fc:
                    fc.remove(i)
            fr-=h1
    print("Ashish" if min(fr,len(fc))&1 else "Vivek")


for i in range(int(input())):
    n,m=map(int,input().split())
    fr,fc=n,set([i for i in range(m)])
    for i in range(n):
        r=input()
        h1=0
        for i in range(m):
            if r[i]=="1":
                h1=1
                if i in fc:
                    fc.remove(i)
            fr-=h1
    print("Ashish" if min(fr,len(fc))&2 else "Vivek")


for i in range(int(input())):
    n,m=map(int,input().split())
    fr,fc=n,set([i for i in range(m)])
    for i in range(n):
        r=input().split()
        h1=0
        for i in range(m):
            if r[i]=="1":
                h1=1
                if i in fc:
                    fc.remove(i)
            fr-=h1
    print("Ashish" if min(fr,len(fc))&2 else "Vivek")


for i in range(int(input())):
    n,m=map(int,input().split())
    fr,fc=n,set([i for i in range(m)])
    for i in range(n):
        h1=0
        for i in input():
            if i=="1":
                h1=1
                if i in fc:
                    fc.remove(i)
            fr-=h1
    print("Ashish" if min(fr,len(fc))%2 else "Vivek")


ncases = int(input())
#suppose A = available rows B = available columns
#every time a player makes a move, A -= 1, B -= 1

for i in range(ncases):
    take = input().split(' ')
    rows = int(take[0])
    cols = int(take[1])
    r = 0
    c = 0
    matrix = []
    for j in range(rows):
        take2 = input().split(' ')
        if ('1' not in take2):
            r += 1
        for t in take2:
            t= int(t)
            matrix.append(t)
    for k in range(rows):
        count = k
        count2 = 0
        while (count<len(matrix)):
            ele = matrix[count]
            if (ele == 1):
                break
            else:
                count += cols
                count2 += 1
                if (count2 == rows):
                    c += 1
                    break
    ash = 0
    vivek = 0
    turns = 0
    while (min(r,c)> 0):
        r -= 1
        c -= 1
        if (turns % 2 == 0):
            ash += 1
        else:
            vivek += 1
        turns += 1
    if (ash == vivek):
        print ("Vivek")
    elif (ash>vivek):
        print ("Ashish")
    elif (vivek>ash):
        print ("Vivek")


ncases = int(input())
#suppose A = available rows B = available columns
#every time a player makes a move, A -= 1, B -= 1

for i in range(ncases):
    take = input().split(' ')
    rows = int(take[0])
    cols = int(take[1])
    r = 0
    c = 0
    matrix = []
    for j in range(rows): #count empty rows
        take2 = input().split(' ')
        if ('1' not in take2):
            r += 1
        for t in take2:
            t= int(t)
            matrix.append(t)
    for k in range(cols): #count empty columns
        count = k
        count2 = 0
        while (count<len(matrix)):
            ele = matrix[count]
            if (ele == 1):
                break
            else:
                count += cols
                count2 += 1
                if (count2 == rows):
                    c += 1
                    break
    ash = 0
    vivek = 0
    turns = 0
    while (min(r,c)> 0):
        r -= 1
        c -= 1
        if (turns % 2 == 0):
            ash += 1
        else:
            vivek += 1
        turns += 1
    if (ash == vivek):
        print ("Vivek")
    elif (ash>vivek):
        print ("Ashish")


ncases = int(input())
#suppose A = available rows B = available columns
#every time a player makes a move, A -= 1, B -= 1

for i in range(ncases):
    take = input().split(' ')
    rows = int(take[0])
    cols = int(take[1])
    r = 0
    c = 0
    matrix = []
    for j in range(rows):
        take2 = input().split(' ')
        if ('1' not in take2):
            r += 1
        for t in take2:
            t= int(t)
            matrix.append(t)
    for k in range(rows):
        count = k
        count2 = 0
        while (count<len(matrix)):
            ele = matrix[count]
            if (ele == 1):
                break
            else:
                count += cols
                count2 += 1
                if (count2 == rows):
                    c += 1
                    break
    ash = 0
    vivek = 0
    turns = 0
    while (min(r,c)> 0):
        r -= 1
        c -= 1
        if (turns % 2 == 0):
            ash += 1
        else:
            vivek += 1
        turns += 1
    if (ash == vivek):
        print ("Vivek")
    elif (ash>vivek):
        print ("Ashish")


def numFree(n, m, a):
    numsteps = 0
    for i in range(n):
        for j in range(m):
            if sum(a[i]) == 0 and sum(list(zip(*a))[j]) == 0:
                a[i][j] = 1
                numsteps += 1
    if numsteps % 2 == 0:
        Winner = 'Vivek'
    else:
        Winner = 'Ashish'

    return Winner

t = int(input())

for i in range(t):
    a = []
    n, m = map(int, input().split())

    for k in range(n):
        a.append(list(map(int, input().split())))
    print(numFree(n, m, a))


def numFree(n, m, a):

    zeroStrings = 0
    zeroColumns = 0

    for i in range(n):
        if sum(a[i]) == 0:
            zeroStrings += 1
    for j in range(m):
        if sum(list(zip(*a))[j]) == 0:
            zeroColumns += 1
    StepsNumber = zeroColumns * zeroStrings

    if StepsNumber % 2 != 0 and StepsNumber != 0:
        Winner = 'Vivek'
    elif StepsNumber % 2 == 0 and StepsNumber != 0:
        Winner = 'Ashish'
    else:
        Winner = 'Vivek'

    return Winner, zeroStrings, zeroColumns

t = int(input())

for i in range(t):
    a = []
    n, m = map(int, input().split())

    for k in range(n):
        a.append(list(map(int, input().split())))
    print(numFree(n, m, a))


def numFree(n, m, a):

    zeroStrings = 0
    zeroColumns = 0

    for i in range(n):
        if sum(a[i]) == 0:
            zeroStrings += 1
    for j in range(m):
        if sum(list(zip(*a))[j]) == 0:
            zeroColumns += 1
    StepsNumber = zeroColumns * zeroStrings

    if StepsNumber % 2 != 0 and StepsNumber != 0:
        Winner = 'Vivek'
    elif:
        StepsNumber % 2 == 0 and StepsNumber != 0:
        Winner = 'Ashish'
    else:
        Winner = 'Vivek'

    return Winner, zeroStrings, zeroColumns

t = int(input())

for i in range(t):
    a = []
    n, m = map(int, input().split())

    for k in range(n):
        a.append(list(map(int, input().split())))
    print(numFree(n, m, a))


    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;

    class BinTree:vector<ll>{
        public:
            explicit BinTree(ll k=0) {
                assign(k+1,0);
            }
            ll lowbit(ll k) {
                return k&-k;
            }
            ll sum(ll k) {
                return k>0?sum(k-lowbit(k))+(*this)[k]:0;
            }
            ll last() {
                return size()-1;
            }
            void add(ll k,ll w) {
                if(k>last())return;
                (*this)[k]+=w;
                add(k+lowbit(k),w);
            }
    };

    ll n;
    vector<ll> ps;
    vector<ll> mp;
    BinTree bt0, bt1;

    void solve(){
    	bt0 = BinTree(n*10); bt1 = BinTree(n*10);
    	ll res0 = 0;
    	for(ll p=1; p<=n; p++){
    		ll res = res0;
    		ll pi = mp[p];
    		bt0.add(pi, 1);
    		bt1.add(pi, pi);

			ll l=1, r=n;
			while(l<=r){
				ll m = l + (r-l)/2;
				ll nl = bt0.sum(m);
				if(nl > (p/2)) r = m - 1;
				else l = m + 1;
			}

			ll mi0 = l;

		//	cout<<mi0<<" "<<pi<<endl;

    		ll resf = ll(INT_MAX)*100000;

    		for(ll mi = mi0 - 10; mi<=mi0 + 10; mi++){
    			if(mi <= 0 or mi > n) continue;
    			ll res = res0;
    			if(ps[mi]>p){
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - (cn-1)*cn/2;

    				//cout<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);
    				//cout<<res<<endl;

    			}else{
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - cn - (cn-1)*cn/2;
    				//cout<<"left "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<"right "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);

    			}

    			resf = min(resf, res);

    		}

    		res0 += bt0.sum(n) - bt0.sum(pi);

    		cout<<resf<<" ";

    	}
    	cout<<endl;
    }

    int main(){
    	scanf("%d", &n);
    	ps = vector<ll>(n+1, 0);
    	mp = vector<ll>(n+1, 0);
    	for(ll i=1; i<=n; i++){
    		scanf("%d", &ps[i]);
    		mp[ps[i]] = i;
    	}

    	solve();

    	return 0;
    }


    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;

    class BinTree:vector<ll>{
        public:
            explicit BinTree(ll k=0) {
                assign(k+1,0);
            }
            ll lowbit(ll k) {
                return k&-k;
            }
            ll sum(ll k) {
                return k>0?sum(k-lowbit(k))+(*this)[k]:0;
            }
            ll last() {
                return size()-1;
            }
            void add(ll k,ll w) {
                if(k>last())return;
                (*this)[k]+=w;
                add(k+lowbit(k),w);
            }
    };

    ll n;
    vector<ll> ps;
    vector<ll> mp;
    BinTree bt0, bt1;

    void solve(){
    	bt0 = BinTree(n); bt1 = BinTree(n);
    	ll res0 = 0;
    	ll s = 0;
    	for(ll p=1; p<=n; p++){
    		ll res = res0;
    		ll pi = mp[p];
    		s += pi;
    		ll mi0 = s / p;
    		bt0.add(pi, 1);
    		bt1.add(pi, pi);

    		ll resf = INT_MAX;

    		for(ll mi = 1; mi<=n; mi++){
    			if(mi <= 0 or mi > n) continue;
    			ll res = res0;
    			if(ps[mi]>p){
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - (cn-1)*cn/2;

    				//cout<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);
    				//cout<<res<<endl;

    			}else{
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - cn - (cn-1)*cn/2;
    				//cout<<"left "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<"right "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);

    			}

    			resf = min(resf, res);

    		}

    		res0 += bt0.sum(n) - bt0.sum(pi);

    		cout<<resf<<" ";

    	}
    	cout<<endl;
    }

    int main(){
    	scanf("%d", &n);
    	ps = vector<ll>(n+1, 0);
    	mp = vector<ll>(n+1, 0);
    	for(ll i=1; i<=n; i++){
    		scanf("%d", &ps[i]);
    		mp[ps[i]] = i;
    	}

    	solve();

    	return 0;
    }


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

class BinTree:vector<ll>{
    public:
        explicit BinTree(ll k=0) {
            assign(k+1,0);
        }
        ll lowbit(ll k) {
            return k&-k;
        }
        ll sum(ll k) {
            return k>0?sum(k-lowbit(k))+(*this)[k]:0;
        }
        ll last() {
            return size()-1;
        }
        void add(ll k,ll w) {
            if(k>last())return;
            (*this)[k]+=w;
            add(k+lowbit(k),w);
        }
};

ll n;
vector<ll> ps;
vector<ll> mp;
BinTree bt0, bt1;

void solve(){
	bt0 = BinTree(n); bt1 = BinTree(n);
	ll res0 = 0;
	ll s = 0;
	for(ll p=1; p<=n; p++){
		ll res = res0;
		ll pi = mp[p];
		s += pi;
		ll mi0 = s / p;
		bt0.add(pi, 1);
		bt1.add(pi, pi);

		ll resf = INT_MAX;

		for(ll mi = mi0 - 1; mi <= mi0 + 1; mi++){
			ll res = res0;
			if(ps[mi]>p){
				ll cn = bt0.sum(mi-1);
				ll sn = bt1.sum(mi-1);
				res += cn * mi - sn - (cn-1)*cn/2;

				//cout<<res<<endl;

				cn = bt0.sum(n) - bt0.sum(mi);
				sn = bt1.sum(n) - bt1.sum(mi);
				res += sn - cn * mi - cn - (cn-1)*cn/2;
				//cout<<res<<endl;

				res += bt0.sum(n) - bt0.sum(pi);
				//cout<<res<<endl;

			}else{
				ll cn = bt0.sum(mi-1);
				ll sn = bt1.sum(mi-1);
				res += cn * mi - sn - cn - (cn-1)*cn/2;
				//cout<<"left "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

				cn = bt0.sum(n) - bt0.sum(mi);
				sn = bt1.sum(n) - bt1.sum(mi);
				res += sn - cn * mi - cn - (cn-1)*cn/2;
				//cout<<"right "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

				res += bt0.sum(n) - bt0.sum(pi);

			}

			resf = min(resf, res);

		}

		res0 += bt0.sum(n) - bt0.sum(pi);

		cout<<resf<<" ";

	}
	cout<<endl;
}

int main(){
	scanf("%d", &n);
	ps = vector<ll>(n+1, 0);
	mp = vector<ll>(n+1, 0);
	for(ll i=1; i<=n; i++){
		scanf("%d", &ps[i]);
		mp[ps[i]] = i;
	}

	solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

class BinTree:vector<ll>
{
    public:
        explicit BinTree(ll k=0) {
            assign(k+1,0);
        }
        ll lowbit(ll k) {
            return k&-k;
        }
        ll sum(ll k) {
            return k>0?sum(k-lowbit(k))+(*this)[k]:0;
        }
        ll last() {
            return size()-1;
        }
        void add(ll k,ll w) {
            if(k>last())return;
            (*this)[k]+=w;
            add(k+lowbit(k),w);
        }
};

ll n;
vector<ll> ps;
vector<ll> mp;
vector<ll> ress;
BinTree bt0, bt1;

void solve(){
	bt0 = BinTree(n); bt1 = BinTree(n);
	ress = vector<ll>(n+1, 0);
	ll res0 = 0;
	ll s = 0;
	for(ll p=1; p<=n; p++){
		ll res = res0;
		ll pi = mp[p];
		s += pi;
		ll mi = s / p;
		bt0.add(pi, 1);
		bt1.add(pi, pi);

		if(ps[mi]>p){
			ll cn = bt0.sum(mi-1);
			ll sn = bt1.sum(mi-1);
			res += cn * mi - sn - (cn-1)*cn/2;

			cn = bt0.sum(n) - bt0.sum(mi);
			sn = bt1.sum(n) - bt1.sum(mi);
			res += sn - cn * mi - cn - (cn-1)*cn/2;

			res += bt0.sum(n) - bt0.sum(pi);

		}else{
			ll cn = bt0.sum(mi-1);
			ll sn = bt1.sum(mi-1);
			res += cn * mi - sn - cn - (cn-1)*cn/2;
			//cout<<"left "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

			cn = bt0.sum(n) - bt0.sum(mi);
			sn = bt1.sum(n) - bt1.sum(mi);
			res += sn - cn * mi - cn - (cn-1)*cn/2;
			//cout<<"right "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

			res += bt0.sum(n) - bt0.sum(pi);

		}

		res0 += bt0.sum(n) - bt0.sum(pi);

		cout<<res<<" ";

	}
	cout<<endl;
}

int main(){
	scanf("%d", &n);
	ps = vector<ll>(n+1, 0);
	mp = vector<ll>(n+1, 0);
	for(ll i=1; i<=n; i++){
		scanf("%d", &ps[i]);
		mp[ps[i]] = i;
	}

	solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

class BinTree:vector<ll>{
    public:
        explicit BinTree(ll k=0) {
            assign(k+1,0);
        }
        ll lowbit(ll k) {
            return k&-k;
        }
        ll sum(ll k) {
            return k>0?sum(k-lowbit(k))+(*this)[k]:0;
        }
        ll last() {
            return size()-1;
        }
        void add(ll k,ll w) {
            if(k>last())return;
            (*this)[k]+=w;
            add(k+lowbit(k),w);
        }
};

ll n;
vector<ll> ps;
vector<ll> mp;
BinTree bt0, bt1;

void solve(){
	bt0 = BinTree(n); bt1 = BinTree(n);
	ll res0 = 0;
	ll s = 0;
	for(ll p=1; p<=n; p++){
		ll res = res0;
		ll pi = mp[p];
		s += pi;
		ll mi0 = s / p;
		bt0.add(pi, 1);
		bt1.add(pi, pi);

		ll resf = INT_MAX;

		for(ll mi = mi0 - 1; mi <= mi0 + 1; mi++){
			if(mi <= 0 or mi > n) continue;
			ll res = res0;
			if(ps[mi]>p){
				ll cn = bt0.sum(mi-1);
				ll sn = bt1.sum(mi-1);
				res += cn * mi - sn - (cn-1)*cn/2;

				//cout<<res<<endl;

				cn = bt0.sum(n) - bt0.sum(mi);
				sn = bt1.sum(n) - bt1.sum(mi);
				res += sn - cn * mi - cn - (cn-1)*cn/2;
				//cout<<res<<endl;

				res += bt0.sum(n) - bt0.sum(pi);
				//cout<<res<<endl;

			}else{
				ll cn = bt0.sum(mi-1);
				ll sn = bt1.sum(mi-1);
				res += cn * mi - sn - cn - (cn-1)*cn/2;
				//cout<<"left "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

				cn = bt0.sum(n) - bt0.sum(mi);
				sn = bt1.sum(n) - bt1.sum(mi);
				res += sn - cn * mi - cn - (cn-1)*cn/2;
				//cout<<"right "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

				res += bt0.sum(n) - bt0.sum(pi);

			}

			resf = min(resf, res);

		}

		res0 += bt0.sum(n) - bt0.sum(pi);

		cout<<resf<<" ";

	}
	cout<<endl;
}

int main(){
	scanf("%d", &n);
	ps = vector<ll>(n+1, 0);
	mp = vector<ll>(n+1, 0);
	for(ll i=1; i<=n; i++){
		scanf("%d", &ps[i]);
		mp[ps[i]] = i;
	}

	solve();

	return 0;
}


    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;

    class BinTree:vector<ll>{
        public:
            explicit BinTree(ll k=0) {
                assign(k+1,0);
            }
            ll lowbit(ll k) {
                return k&-k;
            }
            ll sum(ll k) {
                return k>0?sum(k-lowbit(k))+(*this)[k]:0;
            }
            ll last() {
                return size()-1;
            }
            void add(ll k,ll w) {
                if(k>last())return;
                (*this)[k]+=w;
                add(k+lowbit(k),w);
            }
    };

    ll n;
    vector<ll> ps;
    vector<ll> mp;
    BinTree bt0, bt1;

    void solve(){
    	bt0 = BinTree(n); bt1 = BinTree(n);
    	ll res0 = 0;
    	ll s = 0;
    	for(ll p=1; p<=n; p++){
    		ll res = res0;
    		ll pi = mp[p];
    		s += pi;
    		ll mi0 = s / p;
    		bt0.add(pi, 1);
    		bt1.add(pi, pi);

			ll l=1, r=n;
			while(l<=r){
				ll m = l + (r-l)/2;
				ll nl = bt0.sum(m);
				if(nl > (p/2)) r = m - 1;
				else l = m + 1;
			}

			mi0 = l;

		//	cout<<mi0<<" "<<pi<<endl;

    		ll resf = INT_MAX;

    		for(ll mi = mi0 - 2; mi<=mi0 + 2; mi++){
    			if(mi <= 0 or mi > n) continue;
    			ll res = res0;
    			if(ps[mi]>p){
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - (cn-1)*cn/2;

    				//cout<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);
    				//cout<<res<<endl;

    			}else{
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - cn - (cn-1)*cn/2;
    				//cout<<"left "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<"right "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);

    			}

    			resf = min(resf, res);

    		}

    		res0 += bt0.sum(n) - bt0.sum(pi);

    		cout<<resf<<" ";

    	}
    	cout<<endl;
    }

    int main(){
    	scanf("%d", &n);
    	ps = vector<ll>(n+1, 0);
    	mp = vector<ll>(n+1, 0);
    	for(ll i=1; i<=n; i++){
    		scanf("%d", &ps[i]);
    		mp[ps[i]] = i;
    	}

    	solve();

    	return 0;
    }


    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;

    class BinTree:vector<ll>{
        public:
            explicit BinTree(ll k=0) {
                assign(k+1,0);
            }
            ll lowbit(ll k) {
                return k&-k;
            }
            ll sum(ll k) {
                return k>0?sum(k-lowbit(k))+(*this)[k]:0;
            }
            ll last() {
                return size()-1;
            }
            void add(ll k,ll w) {
                if(k>last())return;
                (*this)[k]+=w;
                add(k+lowbit(k),w);
            }
    };

    ll n;
    vector<ll> ps;
    vector<ll> mp;
    BinTree bt0, bt1;

    void solve(){
    	bt0 = BinTree(n); bt1 = BinTree(n);
    	ll res0 = 0;
    	ll s = 0;
    	for(ll p=1; p<=n; p++){
    		ll res = res0;
    		ll pi = mp[p];
    		s += pi;
    		ll mi0 = s / p;
    		bt0.add(pi, 1);
    		bt1.add(pi, pi);

    		ll resf = INT_MAX;

    		for(ll mi = mi0 - 10; mi <= mi0 + 10; mi++){
    			if(mi <= 0 or mi > n) continue;
    			ll res = res0;
    			if(ps[mi]>p){
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - (cn-1)*cn/2;

    				//cout<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);
    				//cout<<res<<endl;

    			}else{
    				ll cn = bt0.sum(mi-1);
    				ll sn = bt1.sum(mi-1);
    				res += cn * mi - sn - cn - (cn-1)*cn/2;
    				//cout<<"left "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				cn = bt0.sum(n) - bt0.sum(mi);
    				sn = bt1.sum(n) - bt1.sum(mi);
    				res += sn - cn * mi - cn - (cn-1)*cn/2;
    				//cout<<"right "<<mi<<" "<<cn<<" "<<sn<<" "<<res<<endl;

    				res += bt0.sum(n) - bt0.sum(pi);

    			}

    			resf = min(resf, res);

    		}

    		res0 += bt0.sum(n) - bt0.sum(pi);

    		cout<<resf<<" ";

    	}
    	cout<<endl;
    }

    int main(){
    	scanf("%d", &n);
    	ps = vector<ll>(n+1, 0);
    	mp = vector<ll>(n+1, 0);
    	for(ll i=1; i<=n; i++){
    		scanf("%d", &ps[i]);
    		mp[ps[i]] = i;
    	}

    	solve();

    	return 0;
    }


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <iostream>

using namespace std;

const int DIV = 1000000007;

#define MAX(a, b) (a < b ? b : a)
#define MIN(a, b) (b < a ? b : a)

class BIT {
private:
    vector<int> t;
public:

    void init(int n) {
        t.assign(n, 0);
    }

    int64_t sum(int i) {
        int64_t result = 0;
        while (i >= 0) {
            result += t[i];
            i = (i & (i + 1)) - 1;
        }
        return result;
    }

    int64_t sum(int l, int r) {
        int64_t result = sum(r);
        if (l > 0)
            result -= sum(l - 1);
        return result;
    }

    void add(int i, int value) {
        while (i < t.size()) {
            t[i] += value;
            i = i | (i + 1);
        }
    }

};

int main(int argc, char* argv[]) {
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int n;
    f >> n;
    vector<int> a(n), p(n);
    for (int i = 0; i < n; i++) {
        f >> a[i];
        a[i]--;
        p[a[i]] = i;
    }
    BIT bit;
    bit.init(n);
    vector<int64_t> inv(n);
    for (int i = n - 1; i >= 0; i--) {
        inv[a[i]] = bit.sum(a[i]);
        bit.add(a[i], 1);
    }
    for (int i = 1; i < n; i++)
        inv[i] += inv[i - 1];

    vector<int64_t> r(n, 0);
    bit.init(n);
    priority_queue<int> left, right;
    left.push(p[0]);
    bit.add(p[0], 1);
    for (int i = 1; i < n; i++) {
        r[i] = r[i - 1];
        int sum = bit.sum(p[i]);
        sum = min(sum, i - sum);
        r[i] -= sum;
        bit.add(p[i], 1);
        int j1, j2;
        if (i % 2 == 0) {
            if (p[i] > -right.top()) {
                right.push(-p[i]);
                j1 = -right.top();
                j2 = p[i];
            }
            else {
                left.push(p[i]);
                j1 = p[i];
                j2 = left.top();
            }
        }
        else {
            if (p[i] > left.top()) {
                right.push(-p[i]);
                j1 = left.top();
                j2 = p[i];
            }
            else {
                j1 = p[i];
                j2 = left.top();
                right.push(-left.top());
                left.pop();
                left.push(p[i]);
            }
        }
        sum = bit.sum(j1, j2);
        sum = j2 - j1 + 1 - sum;
        r[i] += sum;
    }
    for (int i = 0; i < n; i++) {
        r[i] += inv[i];
        printf("%I64d ", r[i]);
    }

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <iostream>

using namespace std;

const int DIV = 1000000007;

#define MAX(a, b) (a < b ? b : a)
#define MIN(a, b) (b < a ? b : a)

class BIT {
private:
    vector<int> t;
public:

    void init(int n) {
        t.assign(n, 0);
    }

    int64_t sum(int i) {
        int64_t result = 0;
        while (i >= 0) {
            result += t[i];
            i = (i & (i + 1)) - 1;
        }
        return result;
    }

    int64_t sum(int l, int r) {
        int64_t result = sum(r);
        if (l > 0)
            result -= sum(l - 1);
        return result;
    }

    void add(int i, int value) {
        while (i < t.size()) {
            t[i] += value;
            i = i | (i + 1);
        }
    }

};

int main(int argc, char* argv[]) {
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int n;
    f >> n;
    vector<int> a(n), p(n);
    for (int i = 0; i < n; i++) {
        f >> a[i];
        a[i]--;
        p[a[i]] = i;
    }
    BIT bit;
    bit.init(n);
    vector<int64_t> inv(n);
    for (int i = n - 1; i >= 0; i--) {
        inv[a[i]] = bit.sum(a[i]);
        bit.add(a[i], 1);
    }
    for (int i = 1; i < n; i++)
        inv[i] += inv[i - 1];

    vector<int64_t> r(n, 0);
    bit.init(n);
    priority_queue<int> left, right;
    left.push(p[0]);
    bit.add(p[0], 1);
    for (int i = 1; i < n; i++) {
        r[i] = r[i - 1];
        int sum = bit.sum(p[i]);
        sum = min(sum, i - sum);
        r[i] -= sum;
        bit.add(p[i], 1);
        int j1, j2;
        if (i % 2 == 0) {
            if (p[i] > -right.top()) {
                left.push(-right.top());
                right.pop();
                right.push(-p[i]);
                j1 = left.top();
                j2 = p[i];
            }
            else {
                left.push(p[i]);
                j1 = p[i];
                j2 = left.top();
            }
        }
        else {
            if (p[i] > left.top()) {
                right.push(-p[i]);
                j1 = left.top();
                j2 = p[i];
            }
            else {
                j1 = p[i];
                j2 = left.top();
                right.push(-left.top());
                left.pop();
                left.push(p[i]);
            }
        }
        sum = bit.sum(j1, j2);
        sum = j2 - j1 + 1 - sum;
        r[i] += sum;
    }
    for (int i = 0; i < n; i++) {
        r[i] += inv[i];
        printf("%I64d ", r[i]);
    }

	return 0;
}


#include <iostream>

using namespace std;
typedef long long ll;
const int N = 200010;
int tr1[N],tr2[N];
int n;
int c[N];
int lowbit(int x)
{
    return x & -x;
}
void ud(int tr[],int x,int d)
{
    for(int i = x;i <= n;i += lowbit(i))
    {
        tr[i] += d;
    }
}
int qur(int tr[],int x)
{
    int ans = 0;
    for(int i = x;i;i -= lowbit(i))
    {
        ans += tr[i];
    }
    return ans;
}
int get_pos(int tr[],int x)
{
    int l = 0,r = n;
    while(l < r)
    {
        int mid = (l + r) >> 1;
        if(qur(tr,mid) >= x)r = mid;
        else l = mid + 1;
    }
    return l;
}
int main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++)
    {
        int x;
        cin >> x;
        c[x] = i;
    }
    int d = 0;
    for(int i = 1;i <= n;i ++)
    {
        ud(tr1,c[i],1);
        ud(tr2,c[i],c[i]);
        d += (i - qur(tr1,c[i]));
        //cout << d << endl;
        int pos = get_pos(tr1,(i + 1) / 2);
        //cout << "pos: " << pos << endl;
        int aa = (i - 1) / 2;
        int bb = i / 2;
        int t1 = (ll)aa * pos - (1 + aa) * aa / 2;
        int t2 = (1ll + bb) * bb / 2 + bb * pos;
        int q1 = qur(tr2,pos - 1);
        int q2 = qur(tr2,n) - qur(tr2,pos);
        ll ans = q2 - t2 + t1 - q1;
        //cout << t1 << ' ' << t2 << ' ' << q1 << ' ' << q2 << endl;
        cout << (ans + d) << ' ';
    }
}


#include <iostream>

using namespace std;
typedef long long ll;
const ll N = 200010;
ll tr1[N],tr2[N];
ll n;
ll c[N];
ll lowbit(ll x)
{
    return x & -x;
}
void ud(ll tr[],ll x,ll d)
{
    for(ll i = x;i <= n;i += lowbit(i))
    {
        tr[i] += d;
    }
}
ll qur(ll tr[],ll x)
{
    ll ans = 0;
    for(ll i = x;i;i -= lowbit(i))
    {
        ans += tr[i];
    }
    return ans;
}
ll get_pos(ll tr[],ll x)
{
    ll l = 0,r = n;
    while(l < r)
    {
        ll mid = (l + r) >> 1;
        if(qur(tr,mid) >= x)r = mid;
        else l = mid + 1;
    }
    return l;
}
int main()
{
    cin >> n;
    for(ll i = 1;i <= n;i ++)
    {
        ll x;
        cin >> x;
        c[x] = i;
    }
    ll d = 0;
    for(ll i = 1;i <= n;i ++)
    {
        ud(tr1,c[i],1);
        ud(tr2,c[i],c[i]);
        d += (i - qur(tr1,c[i]));
        //cout << d << endl;
        ll pos = get_pos(tr1,(i + 1) / 2);
        //cout << "pos: " << pos << endl;
        ll aa = (i - 1) / 2;
        ll bb = i / 2;
        ll t1 = (ll)aa * pos - (1 + aa) * aa / 2;
        ll t2 = (1ll + bb) * bb / 2 + bb * pos;
        ll q1 = qur(tr2,pos - 1);
        ll q2 = qur(tr2,n) - qur(tr2,pos);
        ll ans = q2 - t2 + t1 - q1;
        //cout << t1 << ' ' << t2 << ' ' << q1 << ' ' << q2 << endl;
        cout << (ans + d) << ' ';
    }
}


#include <iostream>

using namespace std;
typedef long long ll;
const int N = 200010;
int tr1[N],tr2[N];
int n;
int c[N];
int lowbit(int x)
{
    return x & -x;
}
void ud(int tr[],int x,int d)
{
    for(int i = x;i <= n;i += lowbit(i))
    {
        tr[i] += d;
    }
}
int qur(int tr[],int x)
{
    int ans = 0;
    for(int i = x;i;i -= lowbit(i))
    {
        ans += tr[i];
    }
    return ans;
}
int get_pos(int tr[],int x)
{
    int l = 0,r = n;
    while(l < r)
    {
        int mid = (l + r) >> 1;
        if(qur(tr,mid) >= x)r = mid;
        else l = mid + 1;
    }
    return l;
}
int main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++)
    {
        int x;
        cin >> x;
        c[x] = i;
    }
    ll d = 0;
    for(int i = 1;i <= n;i ++)
    {
        ud(tr1,c[i],1);
        ud(tr2,c[i],c[i]);
        d += (i - qur(tr1,c[i]));
        //cout << d << endl;
        int pos = get_pos(tr1,(i + 1) / 2);
        //cout << "pos: " << pos << endl;
        int aa = (i - 1) / 2;
        int bb = i / 2;
        ll t1 = (ll)aa * pos - (1 + aa) * aa / 2;
        ll t2 = (1ll + bb) * bb / 2 + bb * pos;
        ll q1 = qur(tr2,pos - 1);
        ll q2 = qur(tr2,n) - qur(tr2,pos);
        ll ans = q2 - t2 + t1 - q1;
        //cout << t1 << ' ' << t2 << ' ' << q1 << ' ' << q2 << endl;
        cout << (ans + d) << ' ';
    }
}


#include <iostream>

using namespace std;
typedef long long ll;
const int N = 200010;
int tr1[N],tr2[N];
int n;
int c[N];
int lowbit(int x)
{
    return x & -x;
}
void ud(int tr[],int x,int d)
{
    for(int i = x;i <= n;i += lowbit(i))
    {
        tr[i] += d;
    }
}
int qur(int tr[],int x)
{
    int ans = 0;
    for(int i = x;i;i -= lowbit(i))
    {
        ans += tr[i];
    }
    return ans;
}
int get_pos(int tr[],int x)
{
    int l = 0,r = n;
    while(l < r)
    {
        int mid = (l + r) >> 1;
        if(qur(tr,mid) >= x)r = mid;
        else l = mid + 1;
    }
    return l;
}
int main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++)
    {
        int x;
        cin >> x;
        c[x] = i;
    }
    int d = 0;
    for(int i = 1;i <= n;i ++)
    {
        ud(tr1,c[i],1);
        ud(tr2,c[i],c[i]);
        d += (i - qur(tr1,c[i]));
        cout << d << endl;
        int pos = get_pos(tr1,(i + 1) / 2);
        int aa = (i - 1) / 2;
        int bb = i / 2;
        int t1 = (ll)aa * pos - (1 + aa) * aa / 2;
        int t2 = (1ll + bb) * bb / 2 + bb * pos;
        int q1 = qur(tr2,pos - 1);
        int q2 = qur(tr2,n) - qur(tr2,pos);
        ll ans = q1 - t1 + t2 - q2;
        //cout << (ans + d) << endl;
    }
}


using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Collections;

public class Program
{
    private int N;
    private int[] P;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        P = sc.IntArray();

        /*
         * 順列p
         *
         * 操作 隣接2値交換
         *
         * 1,2,3,4,5... kを作るための操作回数 f(k)
         *
         * 各f(k)
         */

        /*
         * 集める -> バブルソート
         *
         */

        int[] idx = new int[N + 1];
        for (int i = 0; i < N; i++)
        {
            idx[P[i]] = i;
        }

        var ft = new FenwickTree(N);
        var ft2 = new FenwickTree(N);
        long[] ans = new long[N + 1];
        var set = new Set<int>();
        for (int k = 1; k <= N; k++)
        {
            ans[k] = ans[k - 1];
            // 1~kを集める
            set.Add(idx[k]);
            int target = set[set.Count / 2];
            ft2.Add(idx[k], idx[k]);

            if (k % 2 == 1)
            {
                // 前にk/2個
                // 後ろにk/2個
                ans[k] += ft2.Sum(target + 1, N) - (long) target * (k / 2) - T(k / 2);
                ans[k] += (long) target * (k / 2) - ft2.Sum(target) - T(k / 2);
            }
            else
            {
                // 前にk/2個
                // 後ろにk/2 -1個
                ans[k] += ft2.Sum(target + 1, N) - (long) target * (k / 2 - 1) - T(k / 2 - 1);
                ans[k] += (long) target * (k / 2) - ft2.Sum(target) - T(k / 2);
            }

            // バブルソートの追加分
            ans[k] += ft.Sum(idx[k] + 1, N);
            ft.Add(idx[k], 1);
        }

        Console.WriteLine(string.Join(" ", ans.Skip(1)));
    }

    long T(int n)
    {
        return (long) n * (n + 1) / 2;
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Collections
{
    using System;
    using System.Collections.Generic;

    #region Set

    public class Set<T>
    {
        Node root;
        readonly IComparer<T> comparer;
        readonly Node nil;
        public bool IsMultiSet { get; set; }

        public Set(IComparer<T> comparer)
        {
            nil = new Node(default(T));
            root = nil;
            this.comparer = comparer;
        }

        public Set(Comparison<T> comaprison) : this(Comparer<T>.Create(comaprison))
        {
        }

        public Set() : this(Comparer<T>.Default)
        {
        }

        public bool Add(T v)
        {
            return insert(ref root, v);
        }

        public bool Remove(T v)
        {
            return remove(ref root, v);
        }

        public T this[int index]
        {
            get { return find(root, index); }
        }

        public int Count
        {
            get { return root.Count; }
        }

        public void RemoveAt(int k)
        {
            if (k < 0 || k >= root.Count) throw new ArgumentOutOfRangeException();
            removeAt(ref root, k);
        }

        public T[] Items
        {
            get
            {
                var ret = new T[root.Count];
                var k = 0;
                walk(root, ret, ref k);
                return ret;
            }
        }

        void walk(Node t, T[] a, ref int k)
        {
            if (t.Count == 0) return;
            walk(t.lst, a, ref k);
            a[k++] = t.Key;
            walk(t.rst, a, ref k);
        }

        bool insert(ref Node t, T key)
        {
            if (t.Count == 0)
            {
                t = new Node(key);
                t.lst = t.rst = nil;
                t.Update();
                return true;
            }

            var cmp = comparer.Compare(t.Key, key);
            bool res;
            if (cmp > 0)
                res = insert(ref t.lst, key);
            else if (cmp == 0)
            {
                if (IsMultiSet) res = insert(ref t.lst, key);
                else return false;
            }
            else res = insert(ref t.rst, key);

            balance(ref t);
            return res;
        }

        bool remove(ref Node t, T key)
        {
            if (t.Count == 0) return false;
            var cmp = comparer.Compare(key, t.Key);
            bool ret;
            if (cmp < 0) ret = remove(ref t.lst, key);
            else if (cmp > 0) ret = remove(ref t.rst, key);
            else
            {
                ret = true;
                var k = t.lst.Count;
                if (k == 0)
                {
                    t = t.rst;
                    return true;
                }

                if (t.rst.Count == 0)
                {
                    t = t.lst;
                    return true;
                }

                t.Key = find(t.lst, k - 1);
                removeAt(ref t.lst, k - 1);
            }

            balance(ref t);
            return ret;
        }

        void removeAt(ref Node t, int k)
        {
            var cnt = t.lst.Count;
            if (cnt < k) removeAt(ref t.rst, k - cnt - 1);
            else if (cnt > k) removeAt(ref t.lst, k);
            else
            {
                if (cnt == 0)
                {
                    t = t.rst;
                    return;
                }

                if (t.rst.Count == 0)
                {
                    t = t.lst;
                    return;
                }

                t.Key = find(t.lst, k - 1);
                removeAt(ref t.lst, k - 1);
            }

            balance(ref t);
        }

        void balance(ref Node t)
        {
            var balance = t.lst.Height - t.rst.Height;
            if (balance == -2)
            {
                if (t.rst.lst.Height - t.rst.rst.Height > 0)
                {
                    rotR(ref t.rst);
                }

                rotL(ref t);
            }
            else if (balance == 2)
            {
                if (t.lst.lst.Height - t.lst.rst.Height < 0) rotL(ref t.lst);
                rotR(ref t);
            }
            else t.Update();
        }

        T find(Node t, int k)
        {
            if (k < 0 || k > root.Count) throw new ArgumentOutOfRangeException();
            for (;;)
            {
                if (k == t.lst.Count) return t.Key;
                else if (k < t.lst.Count) t = t.lst;
                else
                {
                    k -= t.lst.Count + 1;
                    t = t.rst;
                }
            }
        }

        public int LowerBound(T v)
        {
            var k = 0;
            var t = root;
            for (;;)
            {
                if (t.Count == 0) return k;
                if (comparer.Compare(v, t.Key) <= 0) t = t.lst;
                else
                {
                    k += t.lst.Count + 1;
                    t = t.rst;
                }
            }
        }

        public int UpperBound(T v)
        {
            var k = 0;
            var t = root;
            for (;;)
            {
                if (t.Count == 0) return k;
                if (comparer.Compare(t.Key, v) <= 0)
                {
                    k += t.lst.Count + 1;
                    t = t.rst;
                }
                else t = t.lst;
            }
        }

        void rotR(ref Node t)
        {
            var l = t.lst;
            t.lst = l.rst;
            l.rst = t;
            t.Update();
            l.Update();
            t = l;
        }

        void rotL(ref Node t)
        {
            var r = t.rst;
            t.rst = r.lst;
            r.lst = t;
            t.Update();
            r.Update();
            t = r;
        }

        class Node
        {
            public Node(T key)
            {
                Key = key;
            }

            public int Count { get; private set; }
            public sbyte Height { get; private set; }
            public T Key { get; set; }
            public Node lst, rst;

            public void Update()
            {
                Count = 1 + lst.Count + rst.Count;
                Height = (sbyte) (1 + Math.Max(lst.Height, rst.Height));
            }

            public override string ToString()
            {
                return string.Format("Count = {0}, Key = {1}", Count, Key);
            }
        }
    }

    #endregion
}

namespace CompLib.Collections
{
    using Num = Int64;

    public class FenwickTree
    {
        private readonly Num[] _array;
        public readonly int Count;

        public FenwickTree(int size)
        {
            _array = new Num[size + 1];
            Count = size;
        }

        /// <summary>
        /// A[i]にnを加算
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Add(int i, Num n)
        {
            i++;
            for (; i <= Count; i += i & -i)
            {
                _array[i] += n;
            }
        }

        /// <summary>
        /// [0,r)の和を求める
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public Num Sum(int r)
        {
            Num result = 0;
            for (; r > 0; r -= r & -r)
            {
                result += _array[r];
            }

            return result;
        }

        /// <summary>
        /// [0,i)の和がw以上になるi
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        public int LowerBound(Num w)
        {
            if (w <= 0) return 0;
            int x = 0;
            int k = 1;
            while (k * 2 < Count) k *= 2;
            for (; k > 0; k /= 2)
            {
                if (x + k < Count && _array[x + k] < w)
                {
                    w -= _array[x + k];
                    x += k;
                }
            }

            return x + 1;
        }

        // [l,r)の和を求める
        public Num Sum(int l, int r) => Sum(r) - Sum(l);
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Collections;

public class Program
{
    private int N;
    private int[] P;

    public void Solve()
    {
        checked
        {
            var sc = new Scanner();
            N = sc.NextInt();
            P = sc.IntArray();

            /*
             * 順列p
             *
             * 操作 隣接2値交換
             *
             * 1,2,3,4,5... kを作るための操作回数 f(k)
             *
             * 各f(k)
             */

            /*
             * 集める -> バブルソート
             *
             */

            int[] idx = new int[N + 1];
            for (int i = 0; i < N; i++)
            {
                idx[P[i]] = i;
            }

            var ft = new FenwickTree(N);
            var ft2 = new FenwickTree(N);
            long[] ans = new long[N + 1];
            long[] bubble = new long[N + 1];
            var set = new Set<int>();
            for (int k = 1; k <= N; k++)
            {
                // 1~kを集める
                set.Add(idx[k]);
                int target = set[set.Count / 2];
                ft2.Add(idx[k], idx[k]);

                if (k % 2 == 1)
                {
                    // 前にk/2個
                    // 後ろにk/2個
                    ans[k] += ft2.Sum(target + 1, N) - (long) target * (k / 2) - T(k / 2);
                    ans[k] += (long) target * (k / 2) - ft2.Sum(target) - T(k / 2);
                }
                else
                {
                    // 前にk/2個
                    // 後ろにk/2 -1個
                    ans[k] += ft2.Sum(target + 1, N) - (long) target * (k / 2 - 1) - T(k / 2 - 1);
                    ans[k] += (long) target * (k / 2) - ft2.Sum(target) - T(k / 2);
                }

                bubble[k] = bubble[k - 1];
                // バブルソートの追加分
                bubble[k] += ft.Sum(idx[k] + 1, N);
                ft.Add(idx[k], 1);

                ans[k] += bubble[k];
            }

            Console.WriteLine(string.Join(" ", ans.Skip(1)));
        }
    }

    long T(int n)
    {
        return (long) n * (n + 1) / 2;
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Collections
{
    using System;
    using System.Collections.Generic;

    #region Set

    public class Set<T>
    {
        Node root;
        readonly IComparer<T> comparer;
        readonly Node nil;
        public bool IsMultiSet { get; set; }

        public Set(IComparer<T> comparer)
        {
            nil = new Node(default(T));
            root = nil;
            this.comparer = comparer;
        }

        public Set(Comparison<T> comaprison) : this(Comparer<T>.Create(comaprison))
        {
        }

        public Set() : this(Comparer<T>.Default)
        {
        }

        public bool Add(T v)
        {
            return insert(ref root, v);
        }

        public bool Remove(T v)
        {
            return remove(ref root, v);
        }

        public T this[int index]
        {
            get { return find(root, index); }
        }

        public int Count
        {
            get { return root.Count; }
        }

        public void RemoveAt(int k)
        {
            if (k < 0 || k >= root.Count) throw new ArgumentOutOfRangeException();
            removeAt(ref root, k);
        }

        public T[] Items
        {
            get
            {
                var ret = new T[root.Count];
                var k = 0;
                walk(root, ret, ref k);
                return ret;
            }
        }

        void walk(Node t, T[] a, ref int k)
        {
            if (t.Count == 0) return;
            walk(t.lst, a, ref k);
            a[k++] = t.Key;
            walk(t.rst, a, ref k);
        }

        bool insert(ref Node t, T key)
        {
            if (t.Count == 0)
            {
                t = new Node(key);
                t.lst = t.rst = nil;
                t.Update();
                return true;
            }

            var cmp = comparer.Compare(t.Key, key);
            bool res;
            if (cmp > 0)
                res = insert(ref t.lst, key);
            else if (cmp == 0)
            {
                if (IsMultiSet) res = insert(ref t.lst, key);
                else return false;
            }
            else res = insert(ref t.rst, key);

            balance(ref t);
            return res;
        }

        bool remove(ref Node t, T key)
        {
            if (t.Count == 0) return false;
            var cmp = comparer.Compare(key, t.Key);
            bool ret;
            if (cmp < 0) ret = remove(ref t.lst, key);
            else if (cmp > 0) ret = remove(ref t.rst, key);
            else
            {
                ret = true;
                var k = t.lst.Count;
                if (k == 0)
                {
                    t = t.rst;
                    return true;
                }

                if (t.rst.Count == 0)
                {
                    t = t.lst;
                    return true;
                }

                t.Key = find(t.lst, k - 1);
                removeAt(ref t.lst, k - 1);
            }

            balance(ref t);
            return ret;
        }

        void removeAt(ref Node t, int k)
        {
            var cnt = t.lst.Count;
            if (cnt < k) removeAt(ref t.rst, k - cnt - 1);
            else if (cnt > k) removeAt(ref t.lst, k);
            else
            {
                if (cnt == 0)
                {
                    t = t.rst;
                    return;
                }

                if (t.rst.Count == 0)
                {
                    t = t.lst;
                    return;
                }

                t.Key = find(t.lst, k - 1);
                removeAt(ref t.lst, k - 1);
            }

            balance(ref t);
        }

        void balance(ref Node t)
        {
            var balance = t.lst.Height - t.rst.Height;
            if (balance == -2)
            {
                if (t.rst.lst.Height - t.rst.rst.Height > 0)
                {
                    rotR(ref t.rst);
                }

                rotL(ref t);
            }
            else if (balance == 2)
            {
                if (t.lst.lst.Height - t.lst.rst.Height < 0) rotL(ref t.lst);
                rotR(ref t);
            }
            else t.Update();
        }

        T find(Node t, int k)
        {
            if (k < 0 || k > root.Count) throw new ArgumentOutOfRangeException();
            for (;;)
            {
                if (k == t.lst.Count) return t.Key;
                else if (k < t.lst.Count) t = t.lst;
                else
                {
                    k -= t.lst.Count + 1;
                    t = t.rst;
                }
            }
        }

        public int LowerBound(T v)
        {
            var k = 0;
            var t = root;
            for (;;)
            {
                if (t.Count == 0) return k;
                if (comparer.Compare(v, t.Key) <= 0) t = t.lst;
                else
                {
                    k += t.lst.Count + 1;
                    t = t.rst;
                }
            }
        }

        public int UpperBound(T v)
        {
            var k = 0;
            var t = root;
            for (;;)
            {
                if (t.Count == 0) return k;
                if (comparer.Compare(t.Key, v) <= 0)
                {
                    k += t.lst.Count + 1;
                    t = t.rst;
                }
                else t = t.lst;
            }
        }

        void rotR(ref Node t)
        {
            var l = t.lst;
            t.lst = l.rst;
            l.rst = t;
            t.Update();
            l.Update();
            t = l;
        }

        void rotL(ref Node t)
        {
            var r = t.rst;
            t.rst = r.lst;
            r.lst = t;
            t.Update();
            r.Update();
            t = r;
        }

        class Node
        {
            public Node(T key)
            {
                Key = key;
            }

            public int Count { get; private set; }
            public sbyte Height { get; private set; }
            public T Key { get; set; }
            public Node lst, rst;

            public void Update()
            {
                Count = 1 + lst.Count + rst.Count;
                Height = (sbyte) (1 + Math.Max(lst.Height, rst.Height));
            }

            public override string ToString()
            {
                return string.Format("Count = {0}, Key = {1}", Count, Key);
            }
        }
    }

    #endregion
}

namespace CompLib.Collections
{
    using Num = Int64;

    public class FenwickTree
    {
        private readonly Num[] _array;
        public readonly int Count;

        public FenwickTree(int size)
        {
            _array = new Num[size + 1];
            Count = size;
        }

        /// <summary>
        /// A[i]にnを加算
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Add(int i, Num n)
        {
            i++;
            for (; i <= Count; i += i & -i)
            {
                _array[i] += n;
            }
        }

        /// <summary>
        /// [0,r)の和を求める
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public Num Sum(int r)
        {
            Num result = 0;
            for (; r > 0; r -= r & -r)
            {
                result += _array[r];
            }

            return result;
        }

        /// <summary>
        /// [0,i)の和がw以上になるi
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        public int LowerBound(Num w)
        {
            if (w <= 0) return 0;
            int x = 0;
            int k = 1;
            while (k * 2 < Count) k *= 2;
            for (; k > 0; k /= 2)
            {
                if (x + k < Count && _array[x + k] < w)
                {
                    w -= _array[x + k];
                    x += k;
                }
            }

            return x + 1;
        }

        // [l,r)の和を求める
        public Num Sum(int l, int r) => Sum(r) - Sum(l);
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Linq;
using CompLib.Util;
using System.Threading;
using CompLib.Collections;

public class Program
{
    private int N;
    private int[] P;

    public void Solve()
    {
        checked
        {
            var sc = new Scanner();
            N = sc.NextInt();
            P = sc.IntArray();

            /*
             * 順列p
             *
             * 操作 隣接2値交換
             *
             * 1,2,3,4,5... kを作るための操作回数 f(k)
             *
             * 各f(k)
             */

            /*
             * 集める -> バブルソート
             *
             */

            int[] idx = new int[N + 1];
            for (int i = 0; i < N; i++)
            {
                idx[P[i]] = i;
            }

            var ft = new FenwickTree(N);
            var ft2 = new FenwickTree(N);
            long[] ans = new long[N + 1];
            var set = new Set<int>();
            for (int k = 1; k <= N; k++)
            {
                ans[k] = ans[k - 1];
                // 1~kを集める
                set.Add(idx[k]);
                int target = set[set.Count / 2];
                ft2.Add(idx[k], idx[k]);

                if (k % 2 == 1)
                {
                    // 前にk/2個
                    // 後ろにk/2個
                    ans[k] += ft2.Sum(target + 1, N) - (long) target * (k / 2) - T(k / 2);
                    ans[k] += (long) target * (k / 2) - ft2.Sum(target) - T(k / 2);
                }
                else
                {
                    // 前にk/2個
                    // 後ろにk/2 -1個
                    ans[k] += ft2.Sum(target + 1, N) - (long) target * (k / 2 - 1) - T(k / 2 - 1);
                    ans[k] += (long) target * (k / 2) - ft2.Sum(target) - T(k / 2);
                }

                // バブルソートの追加分
                ans[k] += ft.Sum(idx[k] + 1, N);
                ft.Add(idx[k], 1);
            }

            Console.WriteLine(string.Join(" ", ans.Skip(1)));
        }
    }

    long T(int n)
    {
        return (long) n * (n + 1) / 2;
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

// https://bitbucket.org/camypaper/complib
namespace CompLib.Collections
{
    using System;
    using System.Collections.Generic;

    #region Set

    public class Set<T>
    {
        Node root;
        readonly IComparer<T> comparer;
        readonly Node nil;
        public bool IsMultiSet { get; set; }

        public Set(IComparer<T> comparer)
        {
            nil = new Node(default(T));
            root = nil;
            this.comparer = comparer;
        }

        public Set(Comparison<T> comaprison) : this(Comparer<T>.Create(comaprison))
        {
        }

        public Set() : this(Comparer<T>.Default)
        {
        }

        public bool Add(T v)
        {
            return insert(ref root, v);
        }

        public bool Remove(T v)
        {
            return remove(ref root, v);
        }

        public T this[int index]
        {
            get { return find(root, index); }
        }

        public int Count
        {
            get { return root.Count; }
        }

        public void RemoveAt(int k)
        {
            if (k < 0 || k >= root.Count) throw new ArgumentOutOfRangeException();
            removeAt(ref root, k);
        }

        public T[] Items
        {
            get
            {
                var ret = new T[root.Count];
                var k = 0;
                walk(root, ret, ref k);
                return ret;
            }
        }

        void walk(Node t, T[] a, ref int k)
        {
            if (t.Count == 0) return;
            walk(t.lst, a, ref k);
            a[k++] = t.Key;
            walk(t.rst, a, ref k);
        }

        bool insert(ref Node t, T key)
        {
            if (t.Count == 0)
            {
                t = new Node(key);
                t.lst = t.rst = nil;
                t.Update();
                return true;
            }

            var cmp = comparer.Compare(t.Key, key);
            bool res;
            if (cmp > 0)
                res = insert(ref t.lst, key);
            else if (cmp == 0)
            {
                if (IsMultiSet) res = insert(ref t.lst, key);
                else return false;
            }
            else res = insert(ref t.rst, key);

            balance(ref t);
            return res;
        }

        bool remove(ref Node t, T key)
        {
            if (t.Count == 0) return false;
            var cmp = comparer.Compare(key, t.Key);
            bool ret;
            if (cmp < 0) ret = remove(ref t.lst, key);
            else if (cmp > 0) ret = remove(ref t.rst, key);
            else
            {
                ret = true;
                var k = t.lst.Count;
                if (k == 0)
                {
                    t = t.rst;
                    return true;
                }

                if (t.rst.Count == 0)
                {
                    t = t.lst;
                    return true;
                }

                t.Key = find(t.lst, k - 1);
                removeAt(ref t.lst, k - 1);
            }

            balance(ref t);
            return ret;
        }

        void removeAt(ref Node t, int k)
        {
            var cnt = t.lst.Count;
            if (cnt < k) removeAt(ref t.rst, k - cnt - 1);
            else if (cnt > k) removeAt(ref t.lst, k);
            else
            {
                if (cnt == 0)
                {
                    t = t.rst;
                    return;
                }

                if (t.rst.Count == 0)
                {
                    t = t.lst;
                    return;
                }

                t.Key = find(t.lst, k - 1);
                removeAt(ref t.lst, k - 1);
            }

            balance(ref t);
        }

        void balance(ref Node t)
        {
            var balance = t.lst.Height - t.rst.Height;
            if (balance == -2)
            {
                if (t.rst.lst.Height - t.rst.rst.Height > 0)
                {
                    rotR(ref t.rst);
                }

                rotL(ref t);
            }
            else if (balance == 2)
            {
                if (t.lst.lst.Height - t.lst.rst.Height < 0) rotL(ref t.lst);
                rotR(ref t);
            }
            else t.Update();
        }

        T find(Node t, int k)
        {
            if (k < 0 || k > root.Count) throw new ArgumentOutOfRangeException();
            for (;;)
            {
                if (k == t.lst.Count) return t.Key;
                else if (k < t.lst.Count) t = t.lst;
                else
                {
                    k -= t.lst.Count + 1;
                    t = t.rst;
                }
            }
        }

        public int LowerBound(T v)
        {
            var k = 0;
            var t = root;
            for (;;)
            {
                if (t.Count == 0) return k;
                if (comparer.Compare(v, t.Key) <= 0) t = t.lst;
                else
                {
                    k += t.lst.Count + 1;
                    t = t.rst;
                }
            }
        }

        public int UpperBound(T v)
        {
            var k = 0;
            var t = root;
            for (;;)
            {
                if (t.Count == 0) return k;
                if (comparer.Compare(t.Key, v) <= 0)
                {
                    k += t.lst.Count + 1;
                    t = t.rst;
                }
                else t = t.lst;
            }
        }

        void rotR(ref Node t)
        {
            var l = t.lst;
            t.lst = l.rst;
            l.rst = t;
            t.Update();
            l.Update();
            t = l;
        }

        void rotL(ref Node t)
        {
            var r = t.rst;
            t.rst = r.lst;
            r.lst = t;
            t.Update();
            r.Update();
            t = r;
        }

        class Node
        {
            public Node(T key)
            {
                Key = key;
            }

            public int Count { get; private set; }
            public sbyte Height { get; private set; }
            public T Key { get; set; }
            public Node lst, rst;

            public void Update()
            {
                Count = 1 + lst.Count + rst.Count;
                Height = (sbyte) (1 + Math.Max(lst.Height, rst.Height));
            }

            public override string ToString()
            {
                return string.Format("Count = {0}, Key = {1}", Count, Key);
            }
        }
    }

    #endregion
}

namespace CompLib.Collections
{
    using Num = Int64;

    public class FenwickTree
    {
        private readonly Num[] _array;
        public readonly int Count;

        public FenwickTree(int size)
        {
            _array = new Num[size + 1];
            Count = size;
        }

        /// <summary>
        /// A[i]にnを加算
        /// </summary>
        /// <param name="i"></param>
        /// <param name="n"></param>
        public void Add(int i, Num n)
        {
            i++;
            for (; i <= Count; i += i & -i)
            {
                _array[i] += n;
            }
        }

        /// <summary>
        /// [0,r)の和を求める
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public Num Sum(int r)
        {
            Num result = 0;
            for (; r > 0; r -= r & -r)
            {
                result += _array[r];
            }

            return result;
        }

        /// <summary>
        /// [0,i)の和がw以上になるi
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        public int LowerBound(Num w)
        {
            if (w <= 0) return 0;
            int x = 0;
            int k = 1;
            while (k * 2 < Count) k *= 2;
            for (; k > 0; k /= 2)
            {
                if (x + k < Count && _array[x + k] < w)
                {
                    w -= _array[x + k];
                    x += k;
                }
            }

            return x + 1;
        }

        // [l,r)の和を求める
        public Num Sum(int l, int r) => Sum(r) - Sum(l);
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


n = input()
arr = map(int,raw_input().split(" "))
trees = [0]*(1+n)
dic = [0]*(n+1)
ans = [0]*n

def update(t,i,v):
        while i < len(t):
                t[i] += v
                i += lowbit(i)
def lowbit(x):
        return x&-x
def sum(t,i):
        ans = 0
        while i>0:
                ans += t[i]
                i -= lowbit(i)
        return ans

def getmid(arr,l1,flag):
        low,high = 1,n
        if l1%2 == 0 and  flag:
                midv = l1/2
        else:
                midv = l1/2+1
        while low <= high:
                mid = (low+high)/2
                ret = sum(arr,mid)
                if ret >= midv:
                        high = mid-1
                else:
                        low = mid+1
        return low

for i in range(n):
        dic[arr[i]]=i+1

for i in range(1,n+1):
        ans[i-1] += sum(trees,n)-sum(trees,dic[i])
        if i>=2:
                ans[i-1] += ans[i-2]
        update(trees,dic[i],1)
visited = [0]*(1+n)
mid = 0
last = 0
for i in range(1,n+1):
        update(visited,dic[i],1)
        mid = getmid(visited,i,dic[i]>mid)
        tt = sum(visited,dic[i])
        minus = min(tt-1,i-tt)
        tmp = abs(dic[i]-mid-(tt-sum(visited,mid)))- minus
        ans[i-1] += tmp+last
        last = tmp+last
print " ".join(map(str,ans))


class Fenwick:
    def __init__(self, max_val):
        self.b = [0] * (max_val + 1)

    def update(self, i, increment):
        while i > 0 and i < len(self.b):
            self.b[i] += increment
            i += i & (-i)

    def sum(self, i):
        ans = 0
        while i > 0:
            ans += self.b[i]
            i -= i & (-i)
        return ans

    def at_sum(self, k):
        a, b = 0, len(self.b)
        while a < b:
            mid = (a + b) // 2
            if k <= self.sum(mid):
                b = mid
            else:
                a = mid + 1
        return a

def solve(p):
    pos = [0] * len(p)
    for i, e in enumerate(p):
        pos[e - 1] = i + 1

    ans = 0
    fenwick = Fenwick(len(p))
    for i in range(1, len(p) + 1):
        p = pos[i - 1]
        fenwick.update(p, 1)
        r = fenwick.sum(p)
        m = (i + 1) // 2
        if r <= m:
            m = m + (i % 2 == 0)
            ans += fenwick.at_sum(m) - p - m + 1 + i - r
        else:
            ans += p - fenwick.at_sum(m) + m - r
        yield ans

input()
a = [int(_) for _ in input().split()]
print(*solve(a))


from bisect import bisect_right, bisect_left
# instead of AVLTree
class BITbisect():
    def __init__(self, InputProbNumbers):
        # 座圧
        self.ind_to_co = [-10**18]
        self.co_to_ind = {}
        for ind, num in enumerate(sorted(list(set(InputProbNumbers)))):
            self.ind_to_co.append(num)
            self.co_to_ind[num] = ind+1
        self.max = len(self.co_to_ind)
        self.data = [0]*(self.max+1)

    def __str__(self):
        retList = []
        for i in range(1, self.max+1):
            x = self.ind_to_co[i]
            if self.count(x):
                c = self.count(x)
                for _ in range(c):
                    retList.append(x)
        return "[" + ", ".join([str(a) for a in retList]) + "]"

    def __getitem__(self, key):
        key += 1
        s = 0
        ind = 0
        l = self.max.bit_length()
        for i in reversed(range(l)):
            if ind + (1<<i) <= self.max:
                if s + self.data[ind+(1<<i)] < key:
                    s += self.data[ind+(1<<i)]
                    ind += (1<<i)
        if ind == self.max or key < 0:
            raise IndexError("BIT index out of range")
        return self.ind_to_co[ind+1]

    def __len__(self):
        return self._query_sum(self.max)

    def __contains__(self, num):
        if not num in self.co_to_ind:
            return False
        return self.count(num) > 0

    # 0からiまでの区間和
    # 左に進んでいく
    def _query_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    # i番目の要素にxを足す
    # 上に登っていく
    def _add(self, i, x):
        while i <= self.max:
            self.data[i] += x
            i += i & -i

    # 値xを挿入
    def push(self, x):
        if not x in self.co_to_ind:
            raise KeyError("The pushing number didnt initialized")
        self._add(self.co_to_ind[x], 1)

    # 値xを削除
    def delete(self, x):
        if not x in self.co_to_ind:
            raise KeyError("The deleting number didnt initialized")
        if self.count(x) <= 0:
            raise ValueError("The deleting number doesnt exist")
        self._add(self.co_to_ind[x], -1)

    # 要素xの個数
    def count(self, x):
        return self._query_sum(self.co_to_ind[x]) - self._query_sum(self.co_to_ind[x]-1)

    # 値xを超える最低ind
    def bisect_right(self, x):
        if x in self.co_to_ind:
            i = self.co_to_ind[x]
        else:
            i = bisect_right(self.ind_to_co, x) - 1
        return self._query_sum(i)

    # 値xを下回る最低ind
    def bisect_left(self, x):
        if x in self.co_to_ind:
            i = self.co_to_ind[x]
        else:
            i = bisect_left(self.ind_to_co, x)
        if i == 1:
            return 0
        return self._query_sum(i-1)

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

Ind = [0]*(N+1)
for i, a in enumerate(A):
    Ind[a] = i+1

Bit = BITbisect(list(range(N+1)))
ans = [0]
Bit.push(Ind[1])
a = 0
for n in range(2, N+1):
    ind = Ind[n]
    f = Bit.bisect_left(ind)
    #print(Bit)
    l = len(Bit)
    if l%2 == 0:
        if f == l//2:
            a += l//2
        elif f < l//2:
            p1 = Bit[l//2-1]
            a += (p1-ind-1) - (l//2-1) + l-f
        else:
            p2 = Bit[l//2]
            a += (ind-p2-1) - (l//2-1) + l-f
    else:
        p1 = Bit[l//2]
        #print(f, p1, ind, l)
        if f <= l//2:
            a += (p1-ind-1) - l//2 + l-f
        else:
            a += (ind-p1-1) - l//2 + l-f
    ans.append(a)
    Bit.push(ind)

print(*ans, sep=" ")


from bisect import bisect_right, bisect_left
# instead of AVLTree
class BITbisect():
    def __init__(self, InputProbNumbers):
        # 座圧
        self.ind_to_co = [-10**18]
        self.co_to_ind = {}
        for ind, num in enumerate(sorted(list(set(InputProbNumbers)))):
            self.ind_to_co.append(num)
            self.co_to_ind[num] = ind+1
        self.max = len(self.co_to_ind)
        self.data = [0]*(self.max+1)

    def __str__(self):
        retList = []
        for i in range(1, self.max+1):
            x = self.ind_to_co[i]
            if self.count(x):
                c = self.count(x)
                for _ in range(c):
                    retList.append(x)
        return "[" + ", ".join([str(a) for a in retList]) + "]"

    def __getitem__(self, key):
        key += 1
        s = 0
        ind = 0
        l = self.max.bit_length()
        for i in reversed(range(l)):
            if ind + (1<<i) <= self.max:
                if s + self.data[ind+(1<<i)] < key:
                    s += self.data[ind+(1<<i)]
                    ind += (1<<i)
        if ind == self.max or key < 0:
            raise IndexError("BIT index out of range")
        return self.ind_to_co[ind+1]

    def __len__(self):
        return self._query_sum(self.max)

    def __contains__(self, num):
        if not num in self.co_to_ind:
            return False
        return self.count(num) > 0

    # 0からiまでの区間和
    # 左に進んでいく
    def _query_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    # i番目の要素にxを足す
    # 上に登っていく
    def _add(self, i, x):
        while i <= self.max:
            self.data[i] += x
            i += i & -i

    # 値xを挿入
    def push(self, x):
        if not x in self.co_to_ind:
            raise KeyError("The pushing number didnt initialized")
        self._add(self.co_to_ind[x], 1)

    # 値xを削除
    def delete(self, x):
        if not x in self.co_to_ind:
            raise KeyError("The deleting number didnt initialized")
        if self.count(x) <= 0:
            raise ValueError("The deleting number doesnt exist")
        self._add(self.co_to_ind[x], -1)

    # 要素xの個数
    def count(self, x):
        return self._query_sum(self.co_to_ind[x]) - self._query_sum(self.co_to_ind[x]-1)

    # 値xを超える最低ind
    def bisect_right(self, x):
        if x in self.co_to_ind:
            i = self.co_to_ind[x]
        else:
            i = bisect_right(self.ind_to_co, x) - 1
        return self._query_sum(i)

    # 値xを下回る最低ind
    def bisect_left(self, x):
        if x in self.co_to_ind:
            i = self.co_to_ind[x]
        else:
            i = bisect_left(self.ind_to_co, x)
        if i == 1:
            return 0
        return self._query_sum(i-1)

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

Ind = [0]*(N+1)
for i, a in enumerate(A):
    Ind[a] = i+1

Bit = BITbisect(list(range(N+1)))
ans = [0]
Bit.push(Ind[1])
a = 0
for n in range(2, N+1):
    ind = Ind[n]
    f = Bit.bisect_left(ind)
    #print(Bit)
    l = len(Bit)
    if l%2 == 0:
        if f == l//2:
            a += l//2-l//2
        elif f < l//2:
            p1 = Bit[l//2-1]
            a += (p1-ind-1) - (l//2-1) + l-f
        else:
            p2 = Bit[l//2]
            a += (ind-p2-1) - (l//2-1) + l-f
    else:
        p1 = Bit[l//2]
        #print(f, p1, ind, l)
        if f <= l//2:
            a += (p1-ind-1) - l//2 + l-f
        else:
            a += (ind-p1-1) - l//2 + l-f
    ans.append(a)
    Bit.push(ind)

print(*ans, sep=" ")


n = int(input())
a = [0] + list(map(int, input().split()))

pos, bit = [[0] * (n+1), [0] * (n+1)]

def add(i):
    while i <= n:
        bit[i] += 1
        i += i & -i

def sum(i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i & -i
    return res

for i in range(1, n+1):
    pos[a[i]] = i

Max, Min, invSum = [0, n, 0]
for i in range(1, n+1):
    Max = max(Max, pos[i])
    Min = min(Min, pos[i])
    invSum += i - sum(pos[i]) - 1
    print(Max - Min - i + invSum + 1, end=' ')
    add(pos[i])


n = int(input())
a = [0] + list(map(int, input().split()))

pos, pb, ps = [[0] * (n + 1) for x in range(3)]

def add(bit, i, val):
    while i <= n:
        bit[i] += val
        i += i & -i

def sum(bit, i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i & -i
    return res

def find(bit, sum):
    i, t = 0, 0
    if sum == 0:
        return 0
    for k in range(17, -1, -1):
        i += 1 << k
        if i <= n and t + bit[i] < sum:
            t += bit[i]
        else:
            i -= 1 << k
    return i + 1

for i in range(1, n + 1):
    pos[a[i]] = i

invSum = 0
totalSum = 0
for i in range(1, n + 1):
    totalSum += pos[i]
    invSum += i - sum(pb, pos[i]) - 1
    add(pb, pos[i], 1)
    add(ps, pos[i], pos[i])
    mid = find(pb, i // 2)
    if i % 2 == 1:
        mid2 = find(pb, i // 2 + 1)
        seqSum = (i + 1) * (i // 2) // 2
    else:
        mid2 = mid
        seqSum = i * (i // 2) // 2
    leftSum = sum(ps, mid)
    rightSum = totalSum - sum(ps, mid2)
    print(rightSum - leftSum - seqSum + invSum, end=" ")


import sys
input=sys.stdin.readline
from collections import defaultdict
def getsum(BITTree,i):
    s = 0
    while i > 0:
        s += BITTree[i]
        i -= i & (-i)
    return(s)
def updatebit(BITTree , n , i ,v):
    while i <= n:
        #print(i)
        BITTree[i] += v
        i += i & (-i)

n=int(input())
l=[int(i) for i in input().split()]
ind=defaultdict(int)
for i in range(n):
    ind[l[i]]=i+1
ranges=[[ind[1],ind[1]]]
for i in range(2,n+1):
        mina=min(ind[i],ranges[-1][0])
        maxa=max(ind[i],ranges[-1][1])
        ranges.append([mina,maxa])
#print(ranges)
ans=0
store=[0]
#curr,req=ind[1],ind[1]+1

#print(ind)
for k in range(2,n+1):
    lo,hi=ranges[k-1][0],ranges[k-1][1]
    sub=ranges[k-1][1]-ranges[k-1][0]+1
    pq1=[0]*(sub+1)
    count,ans=0,0
    for i in range(hi-1,lo-2,-1):
        if  l[i]<=k:
           ans+=getsum(pq1,l[i])
           count+=1
           updatebit(pq1,len(pq1)-1,l[i],1)
        else:
            ans+=min(count,k-count)
    store.append(ans)
store=' '.join(map(str,store))
sys.stdout.write(store)


#Author:MVP
n = int(input())
arr = list(map(int,input().split()))
trees = [0]*(1+n)
dic = [0]*(n+1)
ans = [0]*n

def update(t,i,v):
        while i < len(t):
                t[i] += v
                i += lowbit(i)
def lowbit(x):
        return x&-x
def sum(t,i):
        ans = 0
        while i>0:
                ans += t[i]
                i -= lowbit(i)
        return ans

def getmid(arr,l1,flag):
        low,high = 1,n
        if l1%2 == 0 and  flag:
                midv = l1//2
        else:
                midv = l1//2+1
        #print(midv,l1,dic[i])
        while low <= high:
                mid = (low+high)//2
                ret = sum(arr,mid)
                if ret >= midv:
                        high = mid-1
                else:
                        low = mid+1
        return low

for i in range(n):
        dic[arr[i]]=i+1

for i in range(1,n+1):
        ans[i-1] += sum(trees,n)-sum(trees,dic[i])
        if i>=2:
                ans[i-1] += ans[i-2]
        update(trees,dic[i],1)
visited = [0]*(1+n)
mid = 0
last = 0
for i in range(1,n+1):
        update(visited,dic[i],1)
        mid = getmid(visited,i,dic[i]>mid)
        tt = sum(visited,dic[i])
        minus = min(tt-1,i-tt)
        tmp = abs(dic[i]-mid-(tt-sum(visited,mid)))- minus
        #print(dic[i],mid,tt,sum(visited,mid),minus,i)
        ans[i-1] += tmp+last
        last = tmp+last
        #print(ans,tmp,last,mid,i,dic[i])
print(" ".join(map(str,ans)))


import sys
input=sys.stdin.readline
from collections import defaultdict
'''def getsum(BITTree,i):
    s = 0
    while i > 0:
        s += BITTree[i]
        i -= i & (-i)
    return(s)
def updatebit(BITTree , n , i ,v):
    while i <= n:
        #print(i)
        BITTree[i] += v
        i += i & (-i)'''

n=int(input())
l=[int(i) for i in input().split()]
#bitTree = [0]*(n+2)
#inversion_counter=0
#print(bitTree)
ind=defaultdict(int)
for i in range(n):
    ind[l[i]]=i+1
ranges=[[ind[1],ind[1]]]
for i in range(2,n+1):
        mina=min(ind[i],ranges[-1][0])
        maxa=max(ind[i],ranges[-1][1])
        ranges.append([mina,maxa])
#print(ranges)
ans=0
store=[0]
#curr,req=ind[1],ind[1]+1

#print(ind)
for k in range(2,n+1):
    lo,hi=ranges[k-1][0],ranges[k-1][1]
    sub=ranges[k-1][1]-ranges[k-1][0]+1
    pq1=[0]*(sub+1)
    count,ans=0,0
    for i in range(hi-1,lo-2,-1):
        if  l[i]<=k:
           ans+=pq1[l[i]]
           count+=1
           for i in range(l[i],len(pq1)):
               pq1[i]+=1
        else:
            ans+=min(count,k-count)
    store.append(ans)
store=' '.join(map(str,store))
sys.stdout.write(store)


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class BIT(val n: Int) {
  private val N =
    if (Integer.highestOneBit(n) == n) n
    else Integer.highestOneBit(n) shl 1

  private val bit = IntArray(N + 1)

  fun sum(i: Int): Int {
    var x = i
    var s = 0
    while(x > 0) {
      s += bit[x]
      x -= x and -x
    }
    return s
  }

  fun add(i: Int, a: Int) {
    var x = i + 1
    while(x <= N) {
      bit[x] += a
      x += x and -x
    }
  }

  private inline fun sub(a: Int, b: Int) = a - b
  private inline fun lt(a: Int, b: Int) = a < b

  fun lowerBound(W: Int): Int {
    var k = N
    var x = 0
    var w = W
    while(k > 0) {
      if (x + k <= N && lt(bit[x + k], w)) {
        w = sub(w, bit[x + k])
        x += k
      }
      k /= 2
    }
    return min(n, x)
  }
}

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val P = na(N, -1)
    val I = IntArray(N)
    for (i in 0 until N) {
      I[P[i]] = i
    }

    val que = BalanceQueue(N)
    val bit = BIT(N)
    var inv = 0L
    val ans = mutableListOf<Long>()
    for (i in 0 until N) {
      inv += i - bit.sum(I[i])
      bit.add(I[i], 1)
      que.add(P[i])
      ans += que.totalCost() + inv
    }
    out.println(ans.joinToString(" "))
  }

  /**
   * 要素が連続になるまで移動するコスト
   * １つになるのではなく隣り合う
   */
  inner class BalanceQueue(N: Int) {

    val L = Queue(N, isL = true)
    val R = Queue(N, isL = false)

    fun add(i: Int) {
      if (!L.isEmpty() && i < L.peek()) {
        L.add(i)
      } else if (!R.isEmpty() && R.peek() < i) {
        R.add(i)
      } else {
        // どっちでもいい
        L.add(i)
      }

      balance()
    }

    fun balance() {
      if (!L.isEmpty()) {
        while(L.size() > R.size() + 1) {
          R.add(L.pop())
        }
      }
      if (!R.isEmpty()) {
        while(R.size() > L.size() + 1) {
          L.add(R.pop())
        }
      }
    }

    fun dump() {
      debug{"$L $R"}
    }

    fun totalCost(): Long {
      val d = if (!L.isEmpty() && !R.isEmpty()) R.peek() - L.peek() - 1 else 0
      val cnt = min(L.size(), R.size())
      return L.sum + R.sum + cnt.toLong() * d
    }

    inner class Queue(val N: Int, val isL: Boolean) {
      fun comp() = run{ if (isL) compareBy<Int> { -it } else compareBy { it }}
      val que = PriorityQueue<Int>(comp())
      val bit = BIT(N)
      var sum = 0L
      fun size() = run{que.size}
      fun isEmpty() = run{que.isEmpty()}
      fun peek() = run{que.peek()}
      fun pos(i: Int) = run{if (isL) N - 1 - i else i}

      override fun toString(): String {
        return "{$que sum:$sum}"
      }

      fun pop(): Int {
        val i = que.poll()
        if (!que.isEmpty()) {
          val len = abs(que.peek() - i) - 1
          sum -= que.size.toLong() * len
        }
        bit.add(pos(i), -1)
        return i
      }

      fun add(i: Int) {
        if (que.isEmpty()) {
          que.add(i)
        } else {
          val prevTop = que.peek()
          que.add(i)
          if (i == que.peek()) {
            // topが変わった
            val len = abs(i - prevTop) - 1
            sum += len.toLong() * (que.size - 1)
          } else {
            // topが変わらない
            val ix = bit.sum(pos(i))
            sum += abs(i - prevTop) - ix
            sum -= que.size - ix - 1
          }
        }
        bit.add(pos(i), 1)
      }
    }
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class BIT(val n: Int) {
  private val N =
    if (Integer.highestOneBit(n) == n) n
    else Integer.highestOneBit(n) shl 1

  private val bit = IntArray(N + 1)

  fun sum(i: Int): Int {
    var x = i
    var s = 0
    while(x > 0) {
      s += bit[x]
      x -= x and -x
    }
    return s
  }

  fun add(i: Int, a: Int) {
    var x = i + 1
    while(x <= N) {
      bit[x] += a
      x += x and -x
    }
  }

  private inline fun sub(a: Int, b: Int) = a - b
  private inline fun lt(a: Int, b: Int) = a < b

  fun lowerBound(W: Int): Int {
    var k = N
    var x = 0
    var w = W
    while(k > 0) {
      if (x + k <= N && lt(bit[x + k], w)) {
        w = sub(w, bit[x + k])
        x += k
      }
      k /= 2
    }
    return min(n, x)
  }
}

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val P = na(N, -1)
    val I = IntArray(N)
    for (i in 0 until N) {
      I[P[i]] = i
    }

    val que = BalanceQueue(N)
    val bit = BIT(N)
    var inv = 0L
    val ans = mutableListOf<Long>()
    for (i in 0 until N) {
      inv += i - bit.sum(I[i])
      bit.add(I[i], 1)
      que.add(I[i])
      ans += que.totalCost() + inv
    }
    out.println(ans.joinToString(" "))
  }

  /**
   * 要素が連続になるまで移動するコスト
   * １つになるのではなく隣り合う
   */
  inner class BalanceQueue(N: Int) {

    val L = Queue(N, isL = true)
    val R = Queue(N, isL = false)

    fun add(i: Int) {
      if (!L.isEmpty() && i < L.peek()) {
        L.add(i)
      } else if (!R.isEmpty() && R.peek() < i) {
        R.add(i)
      } else {
        // どっちでもいい
        L.add(i)
      }

      dump()
      balance()
      dump()
    }

    fun balance() {
      if (!L.isEmpty()) {
        while(L.size() > R.size() + 1) {
          R.add(L.pop())
        }
      }
      if (!R.isEmpty()) {
        while(R.size() > L.size() + 1) {
          L.add(R.pop())
        }
      }
    }

    fun dump() {
      debug{"$L $R"}
    }

    fun totalCost(): Long {
      val d = if (!L.isEmpty() && !R.isEmpty()) R.peek() - L.peek() - 1 else 0
      val cnt = min(L.size(), R.size())
      return L.sum + R.sum + cnt.toLong() * d
    }

    inner class Queue(val N: Int, val isL: Boolean) {
      fun comp() = run{ if (isL) compareBy<Int> { -it } else compareBy { it }}
      val que = PriorityQueue<Int>(comp())
      val bit = BIT(N)
      var sum = 0L
      fun size() = run{que.size}
      fun isEmpty() = run{que.isEmpty()}
      fun peek() = run{que.peek()}
      fun pos(i: Int) = run{if (isL) N - 1 - i else i}

      override fun toString(): String {
        return "{$que sum:$sum}"
      }

      fun pop(): Int {
        val i = que.poll()
        if (!que.isEmpty()) {
          val len = abs(que.peek() - i) - 1
          sum -= que.size.toLong() * len
        }
        bit.add(pos(i), -1)
        return i
      }

      fun add(i: Int) {
        if (que.isEmpty()) {
          que.add(i)
        } else {
          val prevTop = que.peek()
          que.add(i)
          if (i == que.peek()) {
            // topが変わった
            val len = abs(i - prevTop) - 1
            sum += len.toLong() * (que.size - 1)
          } else {
            // topが変わらない
            val ix = bit.sum(pos(i))
            sum += abs(i - prevTop) - ix
            sum -= que.size - ix - 1
          }
        }
        bit.add(pos(i), 1)
      }
    }
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class E {

	public static void main(String[] args) throws Exception {
//		StringTokenizer stok = new StringTokenizer(new Scanner(new File("F:/books/input.txt")).useDelimiter("\\A").next());
		StringTokenizer stok = new StringTokenizer(new Scanner(System.in).useDelimiter("\\A").next());
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(stok.nextToken());
		int[] a = new int[n+1];
		for (int i = 0; i < n; i++) {
			a[Integer.parseInt(stok.nextToken())]=i+1;
		}
		long tot1 = 0,tot2 = 0;
		long[] fen = new long[n+1];
		PriorityQueue<Long> minH = new PriorityQueue<Long>();
		PriorityQueue<Long> maxH = new PriorityQueue<Long>(Collections.reverseOrder());
		long l = Long.MIN_VALUE,r = Long.MAX_VALUE;
		long ls=0,rs=0;
		for(int i=1;i<=n;i++) {
			tot1 += fenwickQ(n,fen)-fenwickQ(a[i],fen);
			fenwickI(a[i],1,fen);
			if(a[i]<=r) {
				maxH.add((long) a[i]);
				ls += a[i];
			}
			else {
				minH.add((long) a[i]);
				rs += a[i];
			}
			if(maxH.size()>minH.size()+1) {
				long v = maxH.poll();
				minH.add(v);
				ls-=v;rs+=v;
			}
			else if(minH.size()>maxH.size()) {
				long v = minH.poll();
				maxH.add(v);
				ls+=v;rs-=v;
			}
			l = maxH.peek();
			r = minH.size()>0?minH.peek():r;
//			System.out.println(minH+"\n"+maxH+"\n"+i);
//			System.out.println(tot1+" "+tot2);
			tot2 += l*maxH.size()-ls;
			tot2 += rs-l*minH.size();
			tot2 -= tr(maxH.size()-1);
			tot2 -= tr(minH.size());
//			System.out.println(tot1+" "+tot2);
//			System.out.println("******");
			sb.append((tot1+tot2)+" ");
			tot2=0;
		}
		System.out.println(sb);
	}

	private static long tr(long n) {
		return (n*(n+1)/2);
	}

	private static void fenwickI(int id, long v, long[] fen) {
		int l = fen.length;
		for(int i=id;i<l;i+=i&-i) {
			fen[i] += v;
		}
	}

	private static long fenwickQ(int id, long[] fen) {
		long ret = 0;
		for(int i=id;i>0;i-=i&-i) {
			ret += fen[i];
		}
		return ret;
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        KIntegers solver = new KIntegers();
        solver.solve(1, in, out);
        out.close();
    }

    static class KIntegers {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            ArrayList<Integer> arr = new ArrayList<>();
            int[] p = new int[N];
            FenwickTree invert = new FenwickTree(N);
            for (int i = 0; i < N; i++) {
                p[i] = in.nextInt();
                arr.add(i);
            }
            Collections.sort(arr, new Comparator<Integer>() {

                public int compare(Integer integer, Integer t1) {
                    return Integer.compare(p[integer], p[t1]);
                }
            });
            int res = 0;
            for (int i = 0; i < N; i++) {
                int nextInd = arr.get(i);
                res += invert.sum(nextInd, N - 1);
                invert.add(nextInd, 1);
                out.println(res);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class FenwickTree {
        public int[] BIT;
        public int size = 0;

        public FenwickTree(int N) {
            BIT = new int[N];
            size = N;
        }

        public FenwickTree(int[] arr) {
            size = arr.length;
            BIT = new int[arr.length];
            for (int i = 0; i < size; i++) {
                add(i, arr[i]);
            }
        }

        public void add(int id, int add) {
            for (int i = id; i < size; i |= i + 1) {
                BIT[i] += add;
            }
        }

        public int sum(int l, int r) {
            return sum(r) - sum(l - 1);
        }

        public int sum(int r) {
            if (r < 0 || r >= size) {
                return 0;
            }
            int res = 0;
            for (int i = r; i >= 0; i = ((i) & (i + 1)) - 1) {
                res += BIT[i];
            }
            return res;
        }

    }
}