#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; struct FenwickTree{ static const int SIZE = 1<<21; int n; vector tree; public: FenwickTree(int n_):tree(SIZE+1){ n = n_; for(int i=0; i=0; i=(i&i+1)-1) s += tree[i]; return s; } }; int main(){ int N; cin >> N; vector A; map mm, mp; rep(i,N){ int a; cin >> a; A.push_back(a); if(mm.count(a) == 0){ mm[a] = 1; } } int cnt = 0; FOR(it,mm){ mp[it->first] = cnt++; } vector B; rep(i,N){ B.push_back(mp[A[i]]); } FenwickTree ft(1<<21); ll sum = N * (ll)(N-1) / 2LL; ll ret = 0; rep(j,N){ int tmp = ft.sum(B[j]); ret -= tmp; ft.add(B[j], 1); } cout << sum + ret << endl; rep(j,N-1){ ft.add(B[j], -1); ll tmp1 = ft.sum(B[j]); ll tmp2 = ft.sum(N+5) - ft.sum(B[j]-1); //cout << tmp2 << " " << tmp1 << endl; ret += tmp2 - tmp1; cout << sum + ret << endl; ft.add(B[j], 1); } return 0; }