#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 5;
int a[N], b[N];
ll cnt;
int n;
void fun(int x, int y) {
	if (x == y)return;
	int mid = (x + y) / 2;
	fun(x, mid), fun(mid + 1, y);
	int p1 = x, p2 = mid + 1, p3 = x;
	while (p3 <= y) {
		if (p1 > mid) {
			b[p3++] = a[p2++];
		}
		else if (p2 > y) {
			b[p3++] = a[p1++];
		}
		else {
			if (a[p1] > a[p2]) {
				cnt += ll(y - p2 + 1);
				b[p3++] = a[p1++];
			}
			else {
				b[p3++] = a[p2++];
			}
		}
	}
	for (int i = x; i <= y; ++i)a[i] = b[i];
}
ll c[N];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)scanf("%d", &a[i]);
	for (int i = 0; i < n; ++i)c[i] = a[i];
	fun(0, n - 1);
	for (ll i = 0; i < n; ++i) {
		printf("%lld\n", cnt);
		cnt += ((ll)n - c[i] - 1ll) - c[i];
	}
	return 0;
}
/** @kutbilimone **/
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define rall(x) (x).rbegin(),(x).rend()
#define all(x) (x).begin(),(x).end()
#define arring(a, n) for(int i = 0; i < n; cin >> a[i++])
#define int long long

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(1+n), sum(1+n), sqr(1+n);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum[i] = a[i] + sum[i-1];
        sqr[i] = a[i]*a[i] + sqr[i-1];
    }

    int res = 0;
    for(int i = 2; i <= n; i++){
        int n = i-1, x = a[i];
        res += n*x*x - 2*x*sum[n] + sqr[n];
    }

    cout << res;

    return 0;
}
