#include using namespace std; using int64 = long long; template< class T > struct BinaryIndexedTree { vector< T > data; BinaryIndexedTree(int sz) { data.assign(++sz, 0); } T sum(int k) { T ret = 0; for(++k; k > 0; k -= k & -k) ret += data[k]; return (ret); } void add(int k, T x) { for(++k; k < data.size(); k += k & -k) data[k] += x; } }; int main() { int N, A[500000]; scanf("%d", &N); vector< int > vs(N); for(int i = 0; i < N; i++) { scanf("%d", &A[i]); vs[i] = A[i]; } sort(begin(vs), end(vs)); vs.erase(unique(begin(vs), end(vs)), end(vs)); for(int i = 0; i < N; i++) { A[i] = lower_bound(begin(vs), end(vs), A[i]) - begin(vs); } BinaryIndexedTree< int > bit(vs.size()); int64 ret = 0; for(int i = N - 1; i >= 0; i--) { ret += bit.sum(A[i]); bit.add(A[i], 1); } cout << ret << endl; for(int i = 0; i < N - 1; i++) { ret -= bit.sum(A[i] - 1); ret += N - bit.sum(A[i]); cout << ret << endl; } }