#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int a[N];
struct fenwick {
  long long fen[N];
  fenwick() { memset(fen, 0, sizeof fen); }
  void add(int x, int d) {
    for (int i = x + 1; i < N; i += i & -i) {
      fen[i] += d;
    }
  }
  long long sum(int x) {
    long long ans = 0;
    for (int i = x; i; i -= i & -i) {
      ans += fen[i];
    }
    return ans;
  }
  long long sum(int l, int r) { return sum(r) - sum(l); }
  int kth(int k) {
    int x = 0;
    for (int i = 17; ~i; i--) {
      if ((x | 1 << i) < N && fen[x | 1 << i] <= k) {
        x |= 1 << i;
        k -= fen[x];
      }
    }
    return x;
  }
} t1, t2;
int solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x] = i;
  }
  long long rev = 0;
  for (int i = 1; i <= n; i++) {
    t1.add(a[i], 1);
    t2.add(a[i], a[i]);
    rev += t1.sum(a[i] + 1, 2e5 + 1);
    int t = i - 1 >> 1;
    int m = t1.kth(t);
    long long mv = 0;
    ++t;
    mv += t2.sum(m + 1, 2e5 + 1) - 1ll * (m + 1) * (i - t) -
          1ll * (i - t) * (i - t - 1) / 2;
    mv += 1ll * m * t - t2.sum(m + 1) - 1ll * t * (t - 1) / 2;
    printf("%lld ", mv + rev);
  }
  puts("");
  return 0;
}
signed main() {
  solve();
  return 0;
}

### Prompt

In CPP, your task is to solve 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 int N = 2e5 + 7;
int a[N];
struct fenwick {
  long long fen[N];
  fenwick() { memset(fen, 0, sizeof fen); }
  void add(int x, int d) {
    for (int i = x + 1; i < N; i += i & -i) {
      fen[i] += d;
    }
  }
  long long sum(int x) {
    long long ans = 0;
    for (int i = x; i; i -= i & -i) {
      ans += fen[i];
    }
    return ans;
  }
  long long sum(int l, int r) { return sum(r) - sum(l); }
  int kth(int k) {
    int x = 0;
    for (int i = 17; ~i; i--) {
      if ((x | 1 << i) < N && fen[x | 1 << i] <= k) {
        x |= 1 << i;
        k -= fen[x];
      }
    }
    return x;
  }
} t1, t2;
int solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x] = i;
  }
  long long rev = 0;
  for (int i = 1; i <= n; i++) {
    t1.add(a[i], 1);
    t2.add(a[i], a[i]);
    rev += t1.sum(a[i] + 1, 2e5 + 1);
    int t = i - 1 >> 1;
    int m = t1.kth(t);
    long long mv = 0;
    ++t;
    mv += t2.sum(m + 1, 2e5 + 1) - 1ll * (m + 1) * (i - t) -
          1ll * (i - t) * (i - t - 1) / 2;
    mv += 1ll * m * t - t2.sum(m + 1) - 1ll * t * (t - 1) / 2;
    printf("%lld ", mv + rev);
  }
  puts("");
  return 0;
}
signed main() {
  solve();
  return 0;
}

```