#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5, MXX = 23;
const long long mod = 1e9 + 7, inf = 1e18 + 6;
int n, a[MX], ind[MX], ver[MX];
void add(int l) {
  for (int i = l + 1; i < MX; i += i & -i) ver[i]++;
}
int ask(int pn) {
  int ans = 0;
  for (pn++; pn; pn -= pn & -pn) ans += ver[pn];
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(9);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) ind[a[i]] = i;
  set<int> nw;
  long long ans = 0;
  int md = ind[1];
  for (int i = 1; i < n + 1; ++i) {
    nw.insert(ind[i]);
    auto v = nw.find(ind[i]);
    add(ind[i]);
    int ver = ask(ind[i]);
    if (i & 1) {
      if (ind[i] > md) md = *next(nw.find(md), 1);
    } else {
      if (ind[i] < md) md = *prev(nw.find(md), 1);
    }
    if (md != ind[i]) {
      int ls = ((i % 2 == 0) && md > ind[i] ? *next(nw.find(md), 1) : md);
      int dis = ls - ind[i];
      dis = max(dis, -dis);
      dis--;
      int fr = ((i % 2 == 0) && md > ind[i] ? (i / 2) : ((i - 1) / 2));
      fr++;
      int bs = ver - fr;
      bs = max(bs, -bs);
      bs--;
      ans += (long long)(dis - bs);
    }
    if (md == ind[i] && (i % 2 == 0)) {
      ans += *next(nw.find(md), 1) - md - 1;
    }
    ans -= (min(i - ver, ver - 1));
    ans += i - ver;
    cout << ans << ' ';
  }
  cout << "\n";
  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 int MX = 2e5 + 5, MXX = 23;
const long long mod = 1e9 + 7, inf = 1e18 + 6;
int n, a[MX], ind[MX], ver[MX];
void add(int l) {
  for (int i = l + 1; i < MX; i += i & -i) ver[i]++;
}
int ask(int pn) {
  int ans = 0;
  for (pn++; pn; pn -= pn & -pn) ans += ver[pn];
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(9);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) ind[a[i]] = i;
  set<int> nw;
  long long ans = 0;
  int md = ind[1];
  for (int i = 1; i < n + 1; ++i) {
    nw.insert(ind[i]);
    auto v = nw.find(ind[i]);
    add(ind[i]);
    int ver = ask(ind[i]);
    if (i & 1) {
      if (ind[i] > md) md = *next(nw.find(md), 1);
    } else {
      if (ind[i] < md) md = *prev(nw.find(md), 1);
    }
    if (md != ind[i]) {
      int ls = ((i % 2 == 0) && md > ind[i] ? *next(nw.find(md), 1) : md);
      int dis = ls - ind[i];
      dis = max(dis, -dis);
      dis--;
      int fr = ((i % 2 == 0) && md > ind[i] ? (i / 2) : ((i - 1) / 2));
      fr++;
      int bs = ver - fr;
      bs = max(bs, -bs);
      bs--;
      ans += (long long)(dis - bs);
    }
    if (md == ind[i] && (i % 2 == 0)) {
      ans += *next(nw.find(md), 1) - md - 1;
    }
    ans -= (min(i - ver, ver - 1));
    ans += i - ver;
    cout << ans << ' ';
  }
  cout << "\n";
  return 0;
}

```