#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
long long sum1[MAXN], sum2[MAXN], a[MAXN], pos[MAXN];
void add1(long long x, long long y) {
  if (!x) return;
  for (; x < MAXN; x += x & -x) {
    sum1[x] += y;
  }
}
long long query1(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) {
    ans += sum1[x];
  }
  return ans;
}
void add2(long long x, long long y) {
  if (!x) return;
  for (; x < MAXN; x += x & -x) {
    sum2[x] += y;
  }
}
long long query2(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) {
    ans += sum2[x];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) {
    memset(sum1, 0, sizeof(sum1));
    memset(sum2, 0, sizeof(sum2));
    long long ans = 0;
    for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i;
    for (int i = 1; i <= n; i++) {
      int p = pos[i];
      add1(p, 1);
      add2(p, p);
      ans += i - query1(p);
      long long pp = ans;
      long long l = 1, r = n, temp;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (query1(mid) * 2 > i) {
          temp = mid;
          r = mid - 1;
        } else
          l = mid + 1;
      }
      long long x = query1(temp);
      pp += (temp - x + 1 + temp) * x / 2 - query2(temp);
      x = i - x;
      pp += query2(n) - query2(temp) - ((temp + 1 + temp + x) * x / 2);
      cout << pp << " ";
    }
    cout << endl;
  }
  return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

You are given a permutation p_1, p_2, …, p_n.

In one move you can swap two adjacent values.

You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k.

Let f(k) be the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation.

You need to find f(1), f(2), …, f(n).

Input

The first line of input contains one integer n (1 ≤ n ≤ 200 000): the number of elements in the permutation.

The next line of input contains n integers p_1, p_2, …, p_n: given permutation (1 ≤ p_i ≤ n).

Output

Print n integers, the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation, for k=1, 2, …, n.

Examples

Input


5
5 4 3 2 1


Output


0 1 3 6 10 


Input


3
1 2 3


Output


0 0 0 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
long long sum1[MAXN], sum2[MAXN], a[MAXN], pos[MAXN];
void add1(long long x, long long y) {
  if (!x) return;
  for (; x < MAXN; x += x & -x) {
    sum1[x] += y;
  }
}
long long query1(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) {
    ans += sum1[x];
  }
  return ans;
}
void add2(long long x, long long y) {
  if (!x) return;
  for (; x < MAXN; x += x & -x) {
    sum2[x] += y;
  }
}
long long query2(long long x) {
  long long ans = 0;
  for (; x; x -= x & -x) {
    ans += sum2[x];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) {
    memset(sum1, 0, sizeof(sum1));
    memset(sum2, 0, sizeof(sum2));
    long long ans = 0;
    for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i;
    for (int i = 1; i <= n; i++) {
      int p = pos[i];
      add1(p, 1);
      add2(p, p);
      ans += i - query1(p);
      long long pp = ans;
      long long l = 1, r = n, temp;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (query1(mid) * 2 > i) {
          temp = mid;
          r = mid - 1;
        } else
          l = mid + 1;
      }
      long long x = query1(temp);
      pp += (temp - x + 1 + temp) * x / 2 - query2(temp);
      x = i - x;
      pp += query2(n) - query2(temp) - ((temp + 1 + temp + x) * x / 2);
      cout << pp << " ";
    }
    cout << endl;
  }
  return 0;
}

```