#include <bits/stdc++.h>
using namespace std;
const long long N = 1000007, inf = 123456789457894;
vector<long long> tree[4 * N];
long long ar[N];
void build(int node, int l, int r) {
  if (l == r) {
    tree[node].push_back(ar[l]);
    return;
  }
  long long left = 2 * node, right = left + 1, m = (l + r) / 2;
  build(left, l, m);
  build(right, m + 1, r);
  merge(tree[left].begin(), tree[left].end(), tree[right].begin(),
        tree[right].end(), back_inserter(tree[node]));
}
long long query(long long node, long long l, long long r, long long i,
                long long j, long long val, int ask) {
  if (r < i || l > j) return 0;
  if (l >= i && r <= j) {
    if (ask == 1) {
      long long x = upper_bound(tree[node].begin(), tree[node].end(), val) -
                    tree[node].begin();
      return (r - l + 1) - x;
    } else
      return lower_bound(tree[node].begin(), tree[node].end(), val) -
             tree[node].begin();
  }
  long long left = 2 * node, right = left + 1, m = (l + r) / 2;
  long long x = query(left, l, m, i, j, val, ask);
  long long y = query(right, m + 1, r, i, j, val, ask);
  return x + y;
}
long long _for[2 * N], _back[2 * N];
int main() {
  ios_base::sync_with_stdio(false);
  long long n, ans = 0, zro = inf;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  for (int i = 1; i <= n; i++) {
    if (!ar[i]) zro = i;
    _for[i] = zro;
  }
  for (int i = n; i > 0; i--) {
    if (!ar[i]) zro = i;
    _back[i] = zro;
  }
  for (int i = 1; i <= n; i++)
    cout << min(abs(i - _for[i]), abs(i - _back[i])) << " ";
  return 0;
}

### Prompt

Your task is to create a cpp solution to the following problem:

You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.

Input

The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ ai ≤ 109).

Output

Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j.

Examples

Input

9
2 1 0 3 0 0 3 2 4


Output

2 1 0 1 0 0 1 2 3 

Input

5
0 1 2 3 4


Output

0 1 2 3 4 

Input

7
5 6 0 1 -2 3 4


Output

2 1 0 1 2 3 4 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1000007, inf = 123456789457894;
vector<long long> tree[4 * N];
long long ar[N];
void build(int node, int l, int r) {
  if (l == r) {
    tree[node].push_back(ar[l]);
    return;
  }
  long long left = 2 * node, right = left + 1, m = (l + r) / 2;
  build(left, l, m);
  build(right, m + 1, r);
  merge(tree[left].begin(), tree[left].end(), tree[right].begin(),
        tree[right].end(), back_inserter(tree[node]));
}
long long query(long long node, long long l, long long r, long long i,
                long long j, long long val, int ask) {
  if (r < i || l > j) return 0;
  if (l >= i && r <= j) {
    if (ask == 1) {
      long long x = upper_bound(tree[node].begin(), tree[node].end(), val) -
                    tree[node].begin();
      return (r - l + 1) - x;
    } else
      return lower_bound(tree[node].begin(), tree[node].end(), val) -
             tree[node].begin();
  }
  long long left = 2 * node, right = left + 1, m = (l + r) / 2;
  long long x = query(left, l, m, i, j, val, ask);
  long long y = query(right, m + 1, r, i, j, val, ask);
  return x + y;
}
long long _for[2 * N], _back[2 * N];
int main() {
  ios_base::sync_with_stdio(false);
  long long n, ans = 0, zro = inf;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  for (int i = 1; i <= n; i++) {
    if (!ar[i]) zro = i;
    _for[i] = zro;
  }
  for (int i = n; i > 0; i--) {
    if (!ar[i]) zro = i;
    _back[i] = zro;
  }
  for (int i = 1; i <= n; i++)
    cout << min(abs(i - _for[i]), abs(i - _back[i])) << " ";
  return 0;
}

```