#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n, a[200010], p[200010], c[200010];
long long inv[200010];
set<int> st;
set<int>::iterator it;
int Lowbit(int x) { return x & (-x); }
void Update(int x, int d) {
  while (x <= n) {
    c[x] += d;
    x += Lowbit(x);
  }
}
int Getsum(int x) {
  int res = 0;
  while (x) {
    res += c[x];
    x -= Lowbit(x);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    p[a[i]] = i;
  }
  cout << "0 ";
  int center = p[1], lnum = 0, rnum = 0;
  long long sum = 0;
  st.insert(p[1]);
  Update(p[1], 1);
  for (int i = 2; i <= n; ++i) {
    inv[i] = Getsum(n) - Getsum(p[i]);
    Update(p[i], 1);
    st.insert(p[i]);
    long long nxt_sum =
        sum + inv[i] + abs(p[i] - center) - abs(Getsum(center) - Getsum(p[i]));
    if (center < p[i])
      nxt_sum -= inv[i];
    else
      nxt_sum -= Getsum(p[i] - 1);
    if (p[i] > center)
      rnum++;
    else
      lnum++;
    if (lnum == rnum + 1) {
      it = st.find(center);
      it--;
      center = (*it);
      lnum--;
      rnum++;
    }
    if (rnum == lnum + 2) {
      it = st.find(center);
      it++;
      nxt_sum -= ((*it) - center - 1);
      center = (*it);
      lnum++;
      rnum--;
    }
    sum = nxt_sum;
    cout << sum << " ";
  }
  cout << endl;
  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 mod = 1000000007;
int n, a[200010], p[200010], c[200010];
long long inv[200010];
set<int> st;
set<int>::iterator it;
int Lowbit(int x) { return x & (-x); }
void Update(int x, int d) {
  while (x <= n) {
    c[x] += d;
    x += Lowbit(x);
  }
}
int Getsum(int x) {
  int res = 0;
  while (x) {
    res += c[x];
    x -= Lowbit(x);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    p[a[i]] = i;
  }
  cout << "0 ";
  int center = p[1], lnum = 0, rnum = 0;
  long long sum = 0;
  st.insert(p[1]);
  Update(p[1], 1);
  for (int i = 2; i <= n; ++i) {
    inv[i] = Getsum(n) - Getsum(p[i]);
    Update(p[i], 1);
    st.insert(p[i]);
    long long nxt_sum =
        sum + inv[i] + abs(p[i] - center) - abs(Getsum(center) - Getsum(p[i]));
    if (center < p[i])
      nxt_sum -= inv[i];
    else
      nxt_sum -= Getsum(p[i] - 1);
    if (p[i] > center)
      rnum++;
    else
      lnum++;
    if (lnum == rnum + 1) {
      it = st.find(center);
      it--;
      center = (*it);
      lnum--;
      rnum++;
    }
    if (rnum == lnum + 2) {
      it = st.find(center);
      it++;
      nxt_sum -= ((*it) - center - 1);
      center = (*it);
      lnum++;
      rnum--;
    }
    sum = nxt_sum;
    cout << sum << " ";
  }
  cout << endl;
  return 0;
}

```