/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.09 21:50:08 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template< typename T > struct BinaryIndexedTree { std::vector< T > data; BinaryIndexedTree(int sz) { data.assign(++sz, 0); } inline T sum(int k) { T ret = 0; for (++k; k > 0; k -= k & -k) ret += data[k]; return (ret); } inline T sum(int left, int right) { return sum(right) - sum(left - 1); } inline void add(int k, T x) { for (++k; k < data.size(); k += k & -k) data[k] += x; } int get(ll k) { ++k; int res = 0; int N = 1; while (N < (int)data.size()) N *= 2; for (int i = N / 2; i > 0; i /= 2) { if (res + i < (int)data.size() && data[res + i] < k) { k = k - data[res + i]; res = res + i; } } return res + 1; } void print() { std::cout << "[ "; for (int i = 0; i < data.size() - 1; i++) { std::cout << sum(i, i); if (i < data.size() - 2) cout << ", "; } std::cout << " ]" << endl; } }; int main() { int n;cin >> n; vector a(n); set st; for (int i = 0; i < n; i++) { cin >> a[i]; st.insert(a[i]); } BinaryIndexedTree bit(st.size()); auto t = st.begin(); map mp; int k = 0; while(t != st.end()) { mp[(*t)] = k; k++; t++; } ll ans = 0; for (int i = 0; i < n; i++) { ans += bit.sum(mp[a[i]]+1,st.size()-1); bit.add(mp[a[i]], 1); } for (int i = 0; i < n; i++) { cout << ans << endl; ans -= bit.sum(mp[a[i]]-1); ans += bit.sum(mp[a[i]] + 1,st.size()-1); } return 0; }