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

struct node{
	long long val = 0;
	node *lc = nullptr, *rc = nullptr;
	node() {}
	node(long long val): val(val) {}
	node(node *lc, node *rc): lc(lc), rc(rc) {
		val += lc->val;
		val += rc->val;
	}
};

typedef node * pnode;

const int maxn = 3e5+4;
int n, a[2*maxn];
pnode roots[2*maxn];
long long ans[maxn];
long long cur_inv = 0;

pnode build(int l, int r){
	if (l == r) return new node();
	int mid = (l+r)/2;
	return new node(build(l,mid),build(mid+1,r));
}

pnode update(pnode p, int l, int r, int pos, int val){
	if (l == r) return new node(p->val + val);
	int mid = (l+r)/2;
	if (pos <= mid) return new node(update(p->lc,l,mid,pos,val),p->rc);
	else return new node(p->lc,update(p->rc,mid+1,r,pos,val));
}

long long query(pnode p, int l, int r, int lb, int rb){
	if (r < lb || l > rb) return 0;
	if (l >= lb && r <= rb) return p->val;
	int mid = (l+r)/2;
	return query(p->lc,l,mid,lb,rb) + query(p->rc,mid+1,r,lb,rb);
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> a[i];
		a[i+n] = a[i];
	}
	roots[0] = build(0,n-1);
	for (int i=0; i<2*n; i++){
		cur_inv += query(roots[i],0,n-1,a[i]+1,n-1);
		if (i >= n) cur_inv -= query(roots[i],0,n-1,0,a[i-n]-1);
		if (i >= n-1) ans[i-n+1] = cur_inv;
		roots[i+1] = update(roots[i],0,n-1,a[i],1);
		if (i >= n-1) roots[i+1] = update(roots[i+1],0,n-1,a[i-n+1],-1); 
	}
	for (int i=0; i<n; i++) cout << ans[i] << "\n";
}

// 0 1 2 3 0 1 2 3
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll read() {
	ll x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
int n, a[300005];
ll c[500005], ans;
void jia(int i,ll x){
	while(i<=n){
		c[i]+=x;
		i+=(i&-i);
	}
}
ll he(int i){
	ll s=0;
	while(i){
		s+=c[i];
		i-=(i&-i);
	}
	return s;
}
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) a[i]=read()+1;
	for(int i=1;i<=n;i++){
		jia(a[i],1);
		ans+=he(n)-he(a[i]);
	}
	cout<<ans<<endl;
	for(int i=1;i<n;i++) {
		ans=ans-(a[i]-1)+(n-a[i]);
		cout<<ans<<endl;
	}
}
