#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
int a[MAX], d[MAX], nxt[MAX];
int main() {
  int n, fs;
  while (cin >> n) {
    for (int i = (0); i <= (n - 1); i++) cin >> a[i];
    int p;
    for (int i = (0); i <= (n - 1); i++) {
      if (a[i] == 0) {
        d[i] = 0;
        for (int j = (i); j >= (0); j--) d[j] = abs(i - j);
        p = i;
        fs = i;
        break;
      }
    }
    for (int i = (p + 1); i <= (n - 1); i++) {
      if (a[i] == 0) {
        nxt[p] = i;
        d[i] = 0;
        p = i;
      }
    }
    nxt[p] = n + 1;
    for (int i = (n - 1); i >= (p); i--) d[i] = abs(i - p);
    for (int i = fs; nxt[i] < n; i = nxt[i]) {
      int x = i, y = nxt[i], cnt = 0;
      while (x <= y) {
        d[x++] = cnt;
        d[y--] = cnt;
        cnt++;
      }
    }
    for (int i = (0); i <= (n - 1); i++) cout << d[i] << " ";
    cout << "\n";
  }
  return 0;
}
