#include <bits/stdc++.h>
using namespace std;
int number[200001];
void cute(int a, int b);
int main() {
  int n, cnt;
  vector<int> object;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> number[i];
    if (number[i] == 0) object.push_back(i);
  }
  for (int i = 1; i < object.size(); i++) {
    cute(object[i - 1], object[i]);
  }
  cnt = 1;
  for (int i = object[0] - 1; i >= 1; i--) number[i] = cnt++;
  cnt = 1;
  for (int i = object[object.size() - 1] + 1; i <= n; i++) number[i] = cnt++;
  for (int i = 1; i <= n; i++) {
    if (i != 1) cout << " ";
    cout << number[i];
  }
  cout << endl;
  return 0;
}
void cute(int a, int b) {
  int n = b - a - 1;
  int temp = n / 2, cnt = 1;
  for (int i = a + 1; i <= a + temp; i++) {
    number[i] = cnt++;
  }
  if (n % 2 == 1) number[a + temp + 1] = cnt;
  cnt--;
  for (int i = b - temp; i <= b - 1; i++) {
    number[i] = cnt--;
  }
}
