#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
long long c[maxn], d[maxn];
long long n;
long long lowbit(long long x) { return x & (-x); }
void update(long long i, long long k) {
  while (i <= n) {
    c[i] += k;
    i += lowbit(i);
  }
}
long long getsum(long long i) {
  long long res = 0;
  while (i > 0) {
    res += c[i];
    i -= lowbit(i);
  }
  return res;
}
void update2(long long i, long long k) {
  while (i <= n) {
    d[i] += k;
    i += lowbit(i);
  }
}
long long getsum2(long long i) {
  long long res = 0;
  while (i > 0) {
    res += d[i];
    i -= lowbit(i);
  }
  return res;
}
long long f[maxn], where[maxn];
long long bs(long long sum) {
  long long l = 0, r = n;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (getsum2(mid) >= sum)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l;
}
long long dc(long long x, long long y) {
  long long len = y - x + 1;
  return (x + y) * len / 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> f[i];
    where[f[i]] = i;
  }
  long long cnt = 0;
  for (long long i = 1; i <= n; ++i) {
    long long pos = where[i];
    update2(pos, 1);
    cnt += i - getsum2(pos);
    update(pos, pos);
    long long base = bs(i / 2 + 1);
    long long lmost = base - i / 2;
    long long rmost = base + i / 2 - ((i + 1) % 2);
    long long t = dc(lmost, base) - dc(base + 1, rmost);
    long long sum = 0;
    sum -= getsum(base);
    sum += getsum(n) - getsum(base);
    cout << sum + t + cnt << " ";
  }
  cout << endl;
  return 0;
}

### Prompt

Your challenge is to write 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 = 2e5 + 5;
long long c[maxn], d[maxn];
long long n;
long long lowbit(long long x) { return x & (-x); }
void update(long long i, long long k) {
  while (i <= n) {
    c[i] += k;
    i += lowbit(i);
  }
}
long long getsum(long long i) {
  long long res = 0;
  while (i > 0) {
    res += c[i];
    i -= lowbit(i);
  }
  return res;
}
void update2(long long i, long long k) {
  while (i <= n) {
    d[i] += k;
    i += lowbit(i);
  }
}
long long getsum2(long long i) {
  long long res = 0;
  while (i > 0) {
    res += d[i];
    i -= lowbit(i);
  }
  return res;
}
long long f[maxn], where[maxn];
long long bs(long long sum) {
  long long l = 0, r = n;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (getsum2(mid) >= sum)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l;
}
long long dc(long long x, long long y) {
  long long len = y - x + 1;
  return (x + y) * len / 2;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> f[i];
    where[f[i]] = i;
  }
  long long cnt = 0;
  for (long long i = 1; i <= n; ++i) {
    long long pos = where[i];
    update2(pos, 1);
    cnt += i - getsum2(pos);
    update(pos, pos);
    long long base = bs(i / 2 + 1);
    long long lmost = base - i / 2;
    long long rmost = base + i / 2 - ((i + 1) % 2);
    long long t = dc(lmost, base) - dc(base + 1, rmost);
    long long sum = 0;
    sum -= getsum(base);
    sum += getsum(n) - getsum(base);
    cout << sum + t + cnt << " ";
  }
  cout << endl;
  return 0;
}

```