#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define lowbit(x) ((x) & -(x))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr double eps = 1e-8;
constexpr int NINF = 0xc0c0c0c0;
constexpr int INF = 0x3f3f3f3f;
constexpr ll mod = 1e9 + 7;
constexpr ll N = 3e5 + 5;

int n, a[N], bit[N], ans[N], l[N], r[N];

void add(int k, int v) {
    for (; k <= n; k += lowbit(k)) bit[k] += v;
}

ll sum(int k) {
    ll ans = 0;
    for (; k; k -= lowbit(k)) ans += bit[k];
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], a[i]++;
    ll res = 0;
    for (int i = n; i; i--) {
        int x = sum(a[i]);
        res += x;
        r[i] = x;
        add(a[i], 1);
    }
    for (int i = 0; i <= n; i++) bit[i] = 0;
    for (int i = 1; i <= n; i++) {
        int x = sum(a[i]);
        l[i] = x;
        add(a[i], 1);
    }
    for (int i = 1; i <= n; i++) {
        cout << res << '\n';
        // res = res - (a[i] - 1) + (n - a[i]);
        res = res - r[i] + (n - i - r[i]) - l[i] + (i - 1 - l[i]);
    }
    return 0;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

bool invalid(vector<double> &i){
	if(i[0] > i[1])
		return true;
	return false;
}

bool inter(vector<double> &i1, vector<double> &i2){
	if(invalid(i1) || invalid(i2))
		return false;
	double nw_s = max(i1[0], i2[0]);
	double nw_e = min(i1[1], i2[1]);
	return (nw_s <= nw_e);
}

void solve()
{
	int n;
	cin >> n;
	vector<vector<double> > interv;
	F(int,i, 0, n - 1, 1){
		double t, st, end;
		cin >> t >> st >> end;
		if(t == 1){
			
		}else if(t == 2){
			end -= 0.2;
		}else if(t == 3){
			st += 0.2;
		}else{
			end -= 0.2;
			st += 0.2;
		}
		// deb(st);deb(end);next_line;
		interv.push_back(vector<double>{st, end});
	}
	int ans = 0;
	F(int, i, 0, n - 1, 1){
		F(int, j, i + 1, n - 1, 1){
			ans += inter(interv[i], interv[j]);
		}
	}
	cout << ans << '\n';
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
		// freopen("Debug.txt", "w", stderr);
	#else
	#endif
	// cout << fixed << setprecision(10);
	int _t = 1;
	// cin>>_t;
	F(int, i, 1, _t, 1){
		// cout << "Case #" << i << ": ";
		solve();
	}
}
