#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0},  {0, -1},
                        {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
template <typename t, typename t1>
t min1(t a, t1 b) {
  return a < b ? a : b;
}
template <typename t, typename... arg>
t min1(t a, arg... arr) {
  return min1(a, min1(arr...));
}
template <typename t, typename t1>
t max1(t a, t1 b) {
  return a > b ? a : b;
}
template <typename t, typename... arg>
t max1(t a, arg... arr) {
  return max1(a, max1(arr...));
}
inline int jud(double a, double b) {
  if (abs(a) < eps && abs(b) < eps)
    return 0;
  else if (abs1(a - b) / max(abs1(a), abs1(b)) < eps)
    return 0;
  if (a < b) return -1;
  return 1;
}
template <typename t>
inline int jud(t a, t b) {
  if (a < b) return -1;
  if (a == b) return 0;
  return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
  if (na == 0) return 0;
  int be = 0, en = na - 1;
  if (*a <= *(a + na - 1)) {
    if (f_lb == 0)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != 1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != -1)
          en = mid;
        else
          be = mid + 1;
      }
    if (f_small && jud(*(a + be), val) == 1) be--;
    if (!f_small && jud(*(a + be), val) == -1) be++;
  } else {
    if (f_lb)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != -1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != 1)
          en = mid;
        else
          be = mid + 1;
      }
    if (!f_small && jud(*(a + be), val) == -1) be--;
    if (f_small && jud(*(a + be), val) == 1) be++;
  }
  return be;
}
template <class T>
inline T lowb(T num) {
  return num & (-num);
}
inline int bitnum(unsigned int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(unsigned long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitnum(long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitmaxl(unsigned int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(unsigned long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
inline int bitmaxl(long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
long long pow(long long n, long long m, long long mod = 0) {
  if (m < 0) return 0;
  long long ans = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (mod) ans %= mod;
    }
    k *= k;
    if (mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
  if (mod == -1) mod = 1000000007;
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
template <class t>
void output1(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) cerr << arr[i] << ' ';
  cerr << endl;
}
template <class t>
void output2(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) output1(arr[i]);
}
template <class t>
struct segment_node {
  int be, en;
  t add;
  pair<t, int> minv;
};
template <class t>
struct segment_tree {
  int l;
  segment_node<t> tree[500100 * 4];
  inline int gleft(int no) { return no << 1; }
  inline int gright(int no) { return (no << 1) + 1; }
  inline int gfa(int no) { return no >> 1; }
  inline segment_tree() { l = 0; }
  void build(int no, int l, int r, t orig = 0) {
    if (l > r) r = l;
    if (l == r) {
      tree[no].be = tree[no].en = l;
      tree[no].add = 0;
      tree[no].minv = make_pair(orig, l);
      return;
    }
    tree[no].be = l;
    tree[no].en = r;
    int mid = (l + r) / 2;
    build(gleft(no), l, mid, orig);
    build(gright(no), mid + 1, r, orig);
    tree[no].add = 0;
    tree[no].minv = min1(tree[gleft(no)].minv, tree[gright(no)].minv);
  }
  inline void relax(int no) {
    int le = gleft(no), ri = gright(no);
    tree[le].add += tree[no].add;
    tree[le].minv.first += tree[no].add;
    tree[ri].add += tree[no].add;
    tree[ri].minv.first += tree[no].add;
    tree[no].add = 0;
  }
  void down(int l, int r, int no, t ranadd) {
    if (r < l) return;
    if (l <= tree[no].be && r >= tree[no].en) {
      tree[no].add += ranadd;
      tree[no].minv.first += ranadd;
      return;
    }
    if (tree[no].add && tree[no].be != tree[no].en) relax(no);
    int mid = (tree[no].be + tree[no].en) >> 1;
    if (r >= tree[no].be && l <= mid) down(l, r, gleft(no), ranadd);
    if (r >= mid + 1 && l <= tree[no].en) down(l, r, gright(no), ranadd);
    tree[no].minv = min1(tree[gleft(no)].minv, tree[gright(no)].minv);
  }
  pair<t, int> getminv(int l, int r, int no) {
    if (l > r) return make_pair(1000000007 + 1000000007, -1);
    if (l <= tree[no].be && r >= tree[no].en) return tree[no].minv;
    if (tree[no].add && tree[no].be != tree[no].en) relax(no);
    pair<t, int> ans = make_pair(1000000007 + 1000000007, -1);
    int mid = (tree[no].be + tree[no].en) >> 1;
    if (r >= tree[no].be && l <= mid) ans = min(ans, getminv(l, r, gleft(no)));
    if (r >= mid + 1 && l <= tree[no].en)
      ans = min(ans, getminv(l, r, gright(no)));
    return ans;
  }
  int getLastNegative(int no = 1) {
    if (tree[no].be == tree[no].en) {
      if (tree[no].minv.first >= 0) return -1;
      return tree[no].be;
    }
    if (tree[no].add && tree[no].be != tree[no].en) relax(no);
    if (tree[gright(no)].minv.first < 0) return getLastNegative(gright(no));
    return getLastNegative(gleft(no));
  }
};
segment_tree<int> sgt;
const int maxn = 500100;
int arr[maxn];
pair<int, int> rarr[maxn];
int n;
int ans;
set<int> have;
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    rarr[i] = make_pair(arr[i], i);
  }
  sort(rarr, rarr + n);
  sgt.build(1, 0, n - 1, 1000000007);
  have.insert(-1);
  for (int i = 0; i < n; i++) {
    int no = find(make_pair(arr[i], i), rarr, n), val = 0;
    auto p = have.lower_bound(no);
    p--;
    int lastNo = *p, lastVal = 0;
    if (lastNo != -1) {
      lastVal = sgt.getminv(lastNo, lastNo, 1).first;
      lastVal = rarr[lastNo].first - lastVal;
      val = lastVal;
      if (rarr[lastNo].first > lastVal) val++;
      if (rarr[lastNo].first < lastVal) val--;
    }
    have.insert(no);
    sgt.down(no, no, 1, (arr[i] - val) - sgt.getminv(no, no, 1).first);
    pair<int, int> rmin = sgt.getminv(no + 1, n - 1, 1);
    bool add = val < arr[i];
    if (val == arr[i]) {
      printf("%d\n", ans);
      continue;
    }
    if (rmin.first < 0) {
      int rno = sgt.getLastNegative();
      sgt.down(no + 1, rno, 1, 1);
      if (sgt.getminv(rno, rno, 1).first != 0) {
        rmin = sgt.getminv(rno + 1, n - 1, 1);
        no = rno;
      } else {
        printf("%d\n", ans);
        continue;
      }
    }
    if (!add) {
      if (rmin.first > 0) {
        sgt.down(no + 1, n - 1, 1, 1);
        ans--;
      } else
        sgt.down(no + 1, rmin.second, 1, 1);
    } else {
      if (rmin.first == 0) {
        int tno = sgt.getminv(no + 1, rmin.second - 1, 1).second;
        sgt.down(no + 1, tno, 1, -1);
      } else if (rmin.first == 1) {
        sgt.down(no + 1, rmin.second, 1, -1);
      } else {
        sgt.down(no + 1, n - 1, 1, -1);
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

### Prompt

Your challenge is to write a CPP solution to the following problem:

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 double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0},  {0, -1},
                        {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
  return a < 0 ? -a : a;
}
template <typename t, typename t1>
t min1(t a, t1 b) {
  return a < b ? a : b;
}
template <typename t, typename... arg>
t min1(t a, arg... arr) {
  return min1(a, min1(arr...));
}
template <typename t, typename t1>
t max1(t a, t1 b) {
  return a > b ? a : b;
}
template <typename t, typename... arg>
t max1(t a, arg... arr) {
  return max1(a, max1(arr...));
}
inline int jud(double a, double b) {
  if (abs(a) < eps && abs(b) < eps)
    return 0;
  else if (abs1(a - b) / max(abs1(a), abs1(b)) < eps)
    return 0;
  if (a < b) return -1;
  return 1;
}
template <typename t>
inline int jud(t a, t b) {
  if (a < b) return -1;
  if (a == b) return 0;
  return 1;
}
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
  if (na == 0) return 0;
  int be = 0, en = na - 1;
  if (*a <= *(a + na - 1)) {
    if (f_lb == 0)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != 1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != -1)
          en = mid;
        else
          be = mid + 1;
      }
    if (f_small && jud(*(a + be), val) == 1) be--;
    if (!f_small && jud(*(a + be), val) == -1) be++;
  } else {
    if (f_lb)
      while (be < en) {
        int mid = (be + en + 1) / 2;
        if (jud(*(a + mid), val) != -1)
          be = mid;
        else
          en = mid - 1;
      }
    else
      while (be < en) {
        int mid = (be + en) / 2;
        if (jud(*(a + mid), val) != 1)
          en = mid;
        else
          be = mid + 1;
      }
    if (!f_small && jud(*(a + be), val) == -1) be--;
    if (f_small && jud(*(a + be), val) == 1) be++;
  }
  return be;
}
template <class T>
inline T lowb(T num) {
  return num & (-num);
}
inline int bitnum(unsigned int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(unsigned long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitnum(long long nValue) {
  return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);
}
inline int bitmaxl(unsigned int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(int a) {
  if (a == 0) return 0;
  return 32 - __builtin_clz(a);
}
inline int bitmaxl(unsigned long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
inline int bitmaxl(long long a) {
  int temp = a >> 32;
  if (temp) return 32 - __builtin_clz(temp) + 32;
  return bitmaxl(int(a));
}
long long pow(long long n, long long m, long long mod = 0) {
  if (m < 0) return 0;
  long long ans = 1;
  long long k = n;
  while (m) {
    if (m & 1) {
      ans *= k;
      if (mod) ans %= mod;
    }
    k *= k;
    if (mod) k %= mod;
    m >>= 1;
  }
  return ans;
}
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
  if (mod == -1) mod = 1000000007;
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
template <class t>
void output1(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) cerr << arr[i] << ' ';
  cerr << endl;
}
template <class t>
void output2(t arr) {
  for (int i = 0; i < (int)arr.size(); i++) output1(arr[i]);
}
template <class t>
struct segment_node {
  int be, en;
  t add;
  pair<t, int> minv;
};
template <class t>
struct segment_tree {
  int l;
  segment_node<t> tree[500100 * 4];
  inline int gleft(int no) { return no << 1; }
  inline int gright(int no) { return (no << 1) + 1; }
  inline int gfa(int no) { return no >> 1; }
  inline segment_tree() { l = 0; }
  void build(int no, int l, int r, t orig = 0) {
    if (l > r) r = l;
    if (l == r) {
      tree[no].be = tree[no].en = l;
      tree[no].add = 0;
      tree[no].minv = make_pair(orig, l);
      return;
    }
    tree[no].be = l;
    tree[no].en = r;
    int mid = (l + r) / 2;
    build(gleft(no), l, mid, orig);
    build(gright(no), mid + 1, r, orig);
    tree[no].add = 0;
    tree[no].minv = min1(tree[gleft(no)].minv, tree[gright(no)].minv);
  }
  inline void relax(int no) {
    int le = gleft(no), ri = gright(no);
    tree[le].add += tree[no].add;
    tree[le].minv.first += tree[no].add;
    tree[ri].add += tree[no].add;
    tree[ri].minv.first += tree[no].add;
    tree[no].add = 0;
  }
  void down(int l, int r, int no, t ranadd) {
    if (r < l) return;
    if (l <= tree[no].be && r >= tree[no].en) {
      tree[no].add += ranadd;
      tree[no].minv.first += ranadd;
      return;
    }
    if (tree[no].add && tree[no].be != tree[no].en) relax(no);
    int mid = (tree[no].be + tree[no].en) >> 1;
    if (r >= tree[no].be && l <= mid) down(l, r, gleft(no), ranadd);
    if (r >= mid + 1 && l <= tree[no].en) down(l, r, gright(no), ranadd);
    tree[no].minv = min1(tree[gleft(no)].minv, tree[gright(no)].minv);
  }
  pair<t, int> getminv(int l, int r, int no) {
    if (l > r) return make_pair(1000000007 + 1000000007, -1);
    if (l <= tree[no].be && r >= tree[no].en) return tree[no].minv;
    if (tree[no].add && tree[no].be != tree[no].en) relax(no);
    pair<t, int> ans = make_pair(1000000007 + 1000000007, -1);
    int mid = (tree[no].be + tree[no].en) >> 1;
    if (r >= tree[no].be && l <= mid) ans = min(ans, getminv(l, r, gleft(no)));
    if (r >= mid + 1 && l <= tree[no].en)
      ans = min(ans, getminv(l, r, gright(no)));
    return ans;
  }
  int getLastNegative(int no = 1) {
    if (tree[no].be == tree[no].en) {
      if (tree[no].minv.first >= 0) return -1;
      return tree[no].be;
    }
    if (tree[no].add && tree[no].be != tree[no].en) relax(no);
    if (tree[gright(no)].minv.first < 0) return getLastNegative(gright(no));
    return getLastNegative(gleft(no));
  }
};
segment_tree<int> sgt;
const int maxn = 500100;
int arr[maxn];
pair<int, int> rarr[maxn];
int n;
int ans;
set<int> have;
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    rarr[i] = make_pair(arr[i], i);
  }
  sort(rarr, rarr + n);
  sgt.build(1, 0, n - 1, 1000000007);
  have.insert(-1);
  for (int i = 0; i < n; i++) {
    int no = find(make_pair(arr[i], i), rarr, n), val = 0;
    auto p = have.lower_bound(no);
    p--;
    int lastNo = *p, lastVal = 0;
    if (lastNo != -1) {
      lastVal = sgt.getminv(lastNo, lastNo, 1).first;
      lastVal = rarr[lastNo].first - lastVal;
      val = lastVal;
      if (rarr[lastNo].first > lastVal) val++;
      if (rarr[lastNo].first < lastVal) val--;
    }
    have.insert(no);
    sgt.down(no, no, 1, (arr[i] - val) - sgt.getminv(no, no, 1).first);
    pair<int, int> rmin = sgt.getminv(no + 1, n - 1, 1);
    bool add = val < arr[i];
    if (val == arr[i]) {
      printf("%d\n", ans);
      continue;
    }
    if (rmin.first < 0) {
      int rno = sgt.getLastNegative();
      sgt.down(no + 1, rno, 1, 1);
      if (sgt.getminv(rno, rno, 1).first != 0) {
        rmin = sgt.getminv(rno + 1, n - 1, 1);
        no = rno;
      } else {
        printf("%d\n", ans);
        continue;
      }
    }
    if (!add) {
      if (rmin.first > 0) {
        sgt.down(no + 1, n - 1, 1, 1);
        ans--;
      } else
        sgt.down(no + 1, rmin.second, 1, 1);
    } else {
      if (rmin.first == 0) {
        int tno = sgt.getminv(no + 1, rmin.second - 1, 1).second;
        sgt.down(no + 1, tno, 1, -1);
      } else if (rmin.first == 1) {
        sgt.down(no + 1, rmin.second, 1, -1);
      } else {
        sgt.down(no + 1, n - 1, 1, -1);
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

```