#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200000 + 10;
long long BIT1[MAXN], BIT2[MAXN];
long long N;
void update(long long p, long long num, long long *BIT) {
  for (; p <= N; p += p & -p) {
    BIT[p] += num;
  }
}
long long query(long long p, long long *BIT) {
  long long sum = 0;
  for (; p > 0; p -= p & -p) {
    sum += BIT[p];
  }
  return sum;
}
long long arr_num[MAXN], arr_pos[MAXN];
signed main(void) {
  cin >> N;
  for (long long i = 1; i <= N; i++) {
    cin >> arr_num[i];
    arr_pos[arr_num[i]] = i;
  }
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    ans += i - query(arr_pos[i], BIT1) - 1;
    update(arr_pos[i], 1, BIT1);
    update(arr_pos[i], arr_pos[i], BIT2);
    long long lb = 1, ub = N;
    while (ub > lb) {
      long long mid = (lb + ub + 1) >> 1;
      if (query(mid - 1, BIT1) > i / 2) {
        ub = mid - 1;
      } else {
        lb = mid;
      }
    }
    long long upper = query(N, BIT1) - query(ub, BIT1);
    long long add1 =
        query(N, BIT2) - query(ub, BIT2) - ub * upper - (1 + upper) * upper / 2;
    long long lower = query(ub - 1, BIT1);
    long long add2 = ub * lower - query(ub - 1, BIT2) - (1 + lower) * lower / 2;
    cout << ans + add1 + add2 << " ";
  }
  cout << endl;
  return 0;
}

### Prompt

Please formulate a Cpp solution to the following problem:

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 long long MAXN = 200000 + 10;
long long BIT1[MAXN], BIT2[MAXN];
long long N;
void update(long long p, long long num, long long *BIT) {
  for (; p <= N; p += p & -p) {
    BIT[p] += num;
  }
}
long long query(long long p, long long *BIT) {
  long long sum = 0;
  for (; p > 0; p -= p & -p) {
    sum += BIT[p];
  }
  return sum;
}
long long arr_num[MAXN], arr_pos[MAXN];
signed main(void) {
  cin >> N;
  for (long long i = 1; i <= N; i++) {
    cin >> arr_num[i];
    arr_pos[arr_num[i]] = i;
  }
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    ans += i - query(arr_pos[i], BIT1) - 1;
    update(arr_pos[i], 1, BIT1);
    update(arr_pos[i], arr_pos[i], BIT2);
    long long lb = 1, ub = N;
    while (ub > lb) {
      long long mid = (lb + ub + 1) >> 1;
      if (query(mid - 1, BIT1) > i / 2) {
        ub = mid - 1;
      } else {
        lb = mid;
      }
    }
    long long upper = query(N, BIT1) - query(ub, BIT1);
    long long add1 =
        query(N, BIT2) - query(ub, BIT2) - ub * upper - (1 + upper) * upper / 2;
    long long lower = query(ub - 1, BIT1);
    long long add2 = ub * lower - query(ub - 1, BIT2) - (1 + lower) * lower / 2;
    cout << ans + add1 + add2 << " ";
  }
  cout << endl;
  return 0;
}

```