#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int N;
int position[maxn];
long long sum1[maxn << 2], sum2[maxn << 2];
void add(long long* bit, int pos, long long val) {
  while (pos <= N) {
    bit[pos] += val;
    pos += pos & (-pos);
  }
}
long long query(long long* bit, int pos) {
  long long ret = 0;
  while (pos) {
    ret += bit[pos];
    pos -= pos & (-pos);
  }
  return ret;
}
int search(long long* bit, int val) {
  int i = 0;
  for (int j = 20; j >= 0; --j) {
    if ((i | (1 << j)) <= N && bit[i | (1 << j)] <= val) {
      val -= bit[i |= (1 << j)];
    }
  }
  return i;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    int p;
    cin >> p;
    position[p] = i;
  }
  long long cnt = 0;
  for (int i = 1; i <= N; ++i) {
    int p = position[i];
    add(sum1, p, 1);
    cnt += i - query(sum1, p);
    add(sum2, p, p);
    long long pos = search(sum1, i / 2) + 1;
    long long sum = 0;
    long long a = i / 2, b = i - a - 1;
    sum += pos * a - a * (a + 1) / 2 - query(sum2, pos - 1);
    sum += (query(sum2, N) - query(sum2, pos)) - b * pos - b * (b + 1) / 2;
    cout << cnt + sum << " ";
  }
  cout << endl;
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

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 + 10;
int N;
int position[maxn];
long long sum1[maxn << 2], sum2[maxn << 2];
void add(long long* bit, int pos, long long val) {
  while (pos <= N) {
    bit[pos] += val;
    pos += pos & (-pos);
  }
}
long long query(long long* bit, int pos) {
  long long ret = 0;
  while (pos) {
    ret += bit[pos];
    pos -= pos & (-pos);
  }
  return ret;
}
int search(long long* bit, int val) {
  int i = 0;
  for (int j = 20; j >= 0; --j) {
    if ((i | (1 << j)) <= N && bit[i | (1 << j)] <= val) {
      val -= bit[i |= (1 << j)];
    }
  }
  return i;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    int p;
    cin >> p;
    position[p] = i;
  }
  long long cnt = 0;
  for (int i = 1; i <= N; ++i) {
    int p = position[i];
    add(sum1, p, 1);
    cnt += i - query(sum1, p);
    add(sum2, p, p);
    long long pos = search(sum1, i / 2) + 1;
    long long sum = 0;
    long long a = i / 2, b = i - a - 1;
    sum += pos * a - a * (a + 1) / 2 - query(sum2, pos - 1);
    sum += (query(sum2, N) - query(sum2, pos)) - b * pos - b * (b + 1) / 2;
    cout << cnt + sum << " ";
  }
  cout << endl;
}

```