#include<bits/stdc++.h>
using namespace std;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define mk(arr,n,type)  type *arr = new type[n]
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ld              long double
#define int              long long
#define nn              '\n'
#define w(t)            cin>>tc; while(tc--)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x,y)       cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define ub(v,x)         upper_bound(v.begin(),v.end(),x)
#define all(x)          x.begin(), x.end()
#define fill(a, b)      memset(a, b, sizeof(a))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
typedef pair<int, int>   pii;
typedef vector<int>      vi;
typedef vector<pii>      vpii;
typedef vector<vi>       vvi;
typedef map<int, int>    mii;
typedef map<char, int>   mci;
typedef map<string, int> msi;
int mpow(int base, int exp);
int lcm(int a, int b);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
vi g[N];

int getSum(int BITree[], int index)
{
	int sum = 0;
	while (index > 0)
	{
		sum += BITree[index];

		index -= index & (-index);
	}
	return sum;
}

void updateBIT(int BITree[], int n, int index, int val)
{
	while (index <= n)
	{
		BITree[index] += val;

		index += index & (-index);
	}
}

void convert(int arr[], int n)
{
	int temp[n];
	for (int i = 0; i < n; i++)
		temp[i] = arr[i];
	sort(temp, temp + n);

	for (int i = 0; i < n; i++)
	{
		arr[i] = lower_bound(temp, temp + n, arr[i]) - temp + 1;
	}
}

int getInvCount(int arr[], int n)
{
	int invcount = 0;
	convert(arr, n);

	int BIT[n + 1];
	for (int i = 1; i <= n; i++)
		BIT[i] = 0;

	for (int i = n - 1; i >= 0; i--)
	{
		invcount += getSum(BIT, arr[i] - 1);

		updateBIT(BIT, n, arr[i], 1);
	}

	return invcount;
}

void sol()
{
	int i, j, k, n, x, y, z, m, tc = 1;
	string s;
	while (tc--)
	{
		cin >> n;
		int a[n];
		int b[n];
		fo(i, n)
		{
			cin >> a[i];
			b[i] = a[i];
		}
		z = getInvCount(b, n);
		fo(i, n)
		{
			cout << z << nn;
			k = a[i];
			x = n - k - 1;
			z = z - k + x;
		}
	}
}

int32_t 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);
#endif

	sol();

	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = (result * base) % mod;
		base = (base * base) % mod;
		exp >>= 1;
	}
	return result;
}

int lcm(int a, int b)
{
	int g = __gcd(a, b);
	return a / g * b;
}

void ipgraph(int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		g[u - 1].pb(v - 1);
		g[v - 1].pb(u - 1);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define INF 0x3F3F3F3F
using namespace std;
struct point {
	int x;
	int y;
	int z;
}Point[17];
int dis(point a, point b)
{
	return abs(b.x - a.x) + abs(b.y - a.y) + max(0, b.z - a.z);
}
int d[18][18];
int dp[1<<18][18];//x下标为已访问点集，用二进制表示,y下标为当前点，dp表示当前点经过剩余点到原点的距离
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> Point[i].x >> Point[i].y >> Point[i].z;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			d[i][j] = dis(Point[i], Point[j]); //保存距离的二维数组

	for (int i = 0; i < (1 << n); i++)
	{
		fill(dp[i], dp[i] + n, INF); 
	}
	dp[(1 << n) - 1][0] = 0; 
	for (int i = (1 << n) - 2; i >= 0; i--) { //i为访问点集
		for (int v = 0; v < n; v++) {//v为当前点
			for (int u = 0; u < n; u++) {//u为中间点
				dp[i][v] = min(dp[i][v], dp[i | 1 << u][u] + d[v][u]);
			}
		}
	}
	cout << dp[0][0];
}
