#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const int mod = 1000000007;
const long long Lbg = 2e18;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
const int msk = 1023;
int na[1000111], b[msk + 1];
int id[1000111], nid[1000111];
void kotori_sort(int a[], int n) {
  for (int i = 1; i <= n; i++) id[i] = i, a[i] += 500000;
  for (int tt = 0; tt < 1; tt++) {
    memset(b, 0, sizeof(b));
    int tmp = 0;
    for (int i = 1; i <= n; i++) b[(a[i] >> tmp) & msk]++;
    for (int i = 1; i <= msk; i++) b[i] += b[i - 1];
    for (int i = n; i >= 1; i--) {
      int x = (a[i] >> tmp) & msk;
      nid[b[x]] = id[i];
      na[b[x]--] = a[i];
    }
    memset(b, 0, sizeof(b));
    tmp = 10;
    for (int i = 1; i <= n; i++) b[(na[i] >> tmp) & msk]++;
    for (int i = 1; i <= msk; i++) b[i] += b[i - 1];
    for (int i = n; i >= 1; i--) {
      int x = (na[i] >> tmp) & msk;
      id[b[x]] = nid[i];
      a[b[x]--] = na[i];
    }
  }
  for (int i = 1; i <= n; i++) a[i] -= 500000;
}
int ia[500111];
struct FruitCandy {
  struct node {
    int mn, lazy;
  } a[2000111];
  int n;
  void pushdown(int p, bool f) {
    int lz = a[p].lazy;
    a[p].lazy = 0;
    if (lz != 0 && f) {
      a[p << 1].lazy += lz;
      a[p << 1].mn += lz;
      a[p << 1 | 1].lazy += lz;
      a[p << 1 | 1].mn += lz;
    }
  }
  void build(int l, int r, int p) {
    if (l == r) {
      a[p].mn = ia[l];
      a[p].lazy = 0;
      return;
    }
    int m = l + r >> 1;
    build(l, m, p << 1);
    build(m + 1, r, p << 1 | 1);
    a[p].mn = min(a[p << 1].mn, a[p << 1 | 1].mn);
  }
  void Build(int N) {
    n = N;
    build(1, n, 1);
  }
  int x, y, v;
  void add(int l, int r, int p) {
    pushdown(p, l < r);
    if (x <= l && r <= y) {
      a[p].lazy += v;
      a[p].mn += v;
      return;
    }
    int m = l + r >> 1;
    if (x <= m) add(l, m, p << 1);
    if (m < y) add(m + 1, r, p << 1 | 1);
    a[p].mn = min(a[p << 1].mn, a[p << 1 | 1].mn);
  }
  void Add(int X, int Y, int V) {
    x = X;
    y = Y;
    v = V;
    add(1, n, 1);
  }
  int Querymn() { return a[1].mn; }
} sgt;
int n, A[500111], a[500111], ans[500111];
int pre[500111], nxt[500111];
bool isd[500111];
void linkdel(int x) {
  pre[nxt[x]] = pre[x];
  nxt[pre[x]] = nxt[x];
  isd[x] = 1;
}
int main() {
  n = getnum();
  for (int i = 1; i <= n; i++) {
    a[i] = getnum();
  }
  kotori_sort(a, n);
  for (int i = 1; i <= n; i++) {
    A[id[i]] = i;
    if (i > 1) pre[i] = i - 1;
    if (i < n) nxt[i] = i + 1;
  }
  for (int i = 1; i <= n; i++) {
    ia[i] = a[i] - i;
  }
  sgt.Build(n);
  int it = 1, itp = 1;
  for (int i = n; i >= 1; i--) {
    while (it <= n && isd[it]) it++;
    while (itp + a[it] <= 0) {
      sgt.Add(it, it, mod);
      sgt.Add(it + 1, n, 1);
      it = nxt[it];
      itp++;
    }
    if (it >= 1 && it <= n) {
      int mn = sgt.Querymn();
      ans[i] = min(-(itp - 1), mn) + i - itp + 1;
    } else
      ans[i] = -i;
    int x = A[i];
    if (x < it)
      itp--;
    else {
      sgt.Add(x, x, mod);
      sgt.Add(x + 1, n, 1);
    }
    linkdel(x);
  }
  for (int i = 1; i <= n; i++) putnum(ans[i]), putendl();
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

It's well-known that blog posts are an important part of Codeforces platform. Every blog post has a global characteristic changing over time — its community rating. A newly created blog post's community rating is 0. Codeforces users may visit the blog post page and rate it, changing its community rating by +1 or -1.

Consider the following model of Codeforces users' behavior. The i-th user has his own estimated blog post rating denoted by an integer ai. When a user visits a blog post page, he compares his estimated blog post rating to its community rating. If his estimated rating is higher, he rates the blog post with +1 (thus, the blog post's community rating increases by 1). If his estimated rating is lower, he rates the blog post with -1 (decreasing its community rating by 1). If the estimated rating and the community rating are equal, user doesn't rate the blog post at all (in this case we'll say that user rates the blog post for 0). In any case, after this procedure user closes the blog post page and never opens it again.

Consider a newly created blog post with the initial community rating of 0. For each of n Codeforces users, numbered from 1 to n, his estimated blog post rating ai is known.

For each k from 1 to n, inclusive, the following question is asked. Let users with indices from 1 to k, in some order, visit the blog post page, rate the blog post and close the page. Each user opens the blog post only after the previous user closes it. What could be the maximum possible community rating of the blog post after these k visits?

Input

The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of Codeforces users.

The second line contains n integers a1, a2, ..., an ( - 5·105 ≤ ai ≤ 5·105) — estimated blog post ratings for users in order from 1 to n.

Output

For each k from 1 to n, output a single integer equal to the maximum possible community rating of the blog post after users with indices from 1 to k, in some order, visit the blog post page, rate the blog post, and close the page.

Examples

Input

4
2 0 2 2


Output

1
1
2
2


Input

7
2 -3 -2 5 0 -3 1


Output

1
0
-1
0
1
1
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const int mod = 1000000007;
const long long Lbg = 2e18;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
const int msk = 1023;
int na[1000111], b[msk + 1];
int id[1000111], nid[1000111];
void kotori_sort(int a[], int n) {
  for (int i = 1; i <= n; i++) id[i] = i, a[i] += 500000;
  for (int tt = 0; tt < 1; tt++) {
    memset(b, 0, sizeof(b));
    int tmp = 0;
    for (int i = 1; i <= n; i++) b[(a[i] >> tmp) & msk]++;
    for (int i = 1; i <= msk; i++) b[i] += b[i - 1];
    for (int i = n; i >= 1; i--) {
      int x = (a[i] >> tmp) & msk;
      nid[b[x]] = id[i];
      na[b[x]--] = a[i];
    }
    memset(b, 0, sizeof(b));
    tmp = 10;
    for (int i = 1; i <= n; i++) b[(na[i] >> tmp) & msk]++;
    for (int i = 1; i <= msk; i++) b[i] += b[i - 1];
    for (int i = n; i >= 1; i--) {
      int x = (na[i] >> tmp) & msk;
      id[b[x]] = nid[i];
      a[b[x]--] = na[i];
    }
  }
  for (int i = 1; i <= n; i++) a[i] -= 500000;
}
int ia[500111];
struct FruitCandy {
  struct node {
    int mn, lazy;
  } a[2000111];
  int n;
  void pushdown(int p, bool f) {
    int lz = a[p].lazy;
    a[p].lazy = 0;
    if (lz != 0 && f) {
      a[p << 1].lazy += lz;
      a[p << 1].mn += lz;
      a[p << 1 | 1].lazy += lz;
      a[p << 1 | 1].mn += lz;
    }
  }
  void build(int l, int r, int p) {
    if (l == r) {
      a[p].mn = ia[l];
      a[p].lazy = 0;
      return;
    }
    int m = l + r >> 1;
    build(l, m, p << 1);
    build(m + 1, r, p << 1 | 1);
    a[p].mn = min(a[p << 1].mn, a[p << 1 | 1].mn);
  }
  void Build(int N) {
    n = N;
    build(1, n, 1);
  }
  int x, y, v;
  void add(int l, int r, int p) {
    pushdown(p, l < r);
    if (x <= l && r <= y) {
      a[p].lazy += v;
      a[p].mn += v;
      return;
    }
    int m = l + r >> 1;
    if (x <= m) add(l, m, p << 1);
    if (m < y) add(m + 1, r, p << 1 | 1);
    a[p].mn = min(a[p << 1].mn, a[p << 1 | 1].mn);
  }
  void Add(int X, int Y, int V) {
    x = X;
    y = Y;
    v = V;
    add(1, n, 1);
  }
  int Querymn() { return a[1].mn; }
} sgt;
int n, A[500111], a[500111], ans[500111];
int pre[500111], nxt[500111];
bool isd[500111];
void linkdel(int x) {
  pre[nxt[x]] = pre[x];
  nxt[pre[x]] = nxt[x];
  isd[x] = 1;
}
int main() {
  n = getnum();
  for (int i = 1; i <= n; i++) {
    a[i] = getnum();
  }
  kotori_sort(a, n);
  for (int i = 1; i <= n; i++) {
    A[id[i]] = i;
    if (i > 1) pre[i] = i - 1;
    if (i < n) nxt[i] = i + 1;
  }
  for (int i = 1; i <= n; i++) {
    ia[i] = a[i] - i;
  }
  sgt.Build(n);
  int it = 1, itp = 1;
  for (int i = n; i >= 1; i--) {
    while (it <= n && isd[it]) it++;
    while (itp + a[it] <= 0) {
      sgt.Add(it, it, mod);
      sgt.Add(it + 1, n, 1);
      it = nxt[it];
      itp++;
    }
    if (it >= 1 && it <= n) {
      int mn = sgt.Querymn();
      ans[i] = min(-(itp - 1), mn) + i - itp + 1;
    } else
      ans[i] = -i;
    int x = A[i];
    if (x < it)
      itp--;
    else {
      sgt.Add(x, x, mod);
      sgt.Add(x + 1, n, 1);
    }
    linkdel(x);
  }
  for (int i = 1; i <= n; i++) putnum(ans[i]), putendl();
  return 0;
}

```