#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)< P; typedef pair pll; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector vd; typedef vector

vp; typedef vector vs; const int MAX_N = 500005; template class BIT { private: int n; vector bit; public: void add(int i,V x){ i++; while(i < n) bit[i] += x, i += i & -i;} V sum(int i){ i++; V s = 0; while(i>0) s += bit[i], i -= i & -i; return s;} BIT(){} BIT(int sz){ n = sz + 1, bit.resize(n,0);} //初期値がすべて0の場合 BIT(vector v){ n = (int)v.size()+1; bit.resize(n); rep(i,n-1) add(i,v[i]);} void print(){ rep(i,n-1)cout<& u) { int n = len(u); BIT bt(n); ll ans = 0; rep(i,n){ ans += i-bt.sum(u[i]); bt.add(u[i],1); } return ans; } ll sm[MAX_N]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vi a(n); rep(i,n){ cin >> a[i]; --a[i]; } vi A = a; zip(A); rep(i,n){ a[i] = lower_bound(all(A),a[i])- A.begin(); } rep(i,len(A)){ sm[i+1] += sm[i] + (upper_bound(all(A),A[i])-lower_bound(all(A),A[i])); } ll res = inv_count(a); rep(i,n){ cout << res << "\n"; res += n-sm[a[i]+1]-sm[a[i]]; } return 0; }