#include <bits/stdc++.h>
using namespace std;

int N;
string S;

long mpow(long a, long b, int m) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m, b >>= 1;
  }
  return res;
}

int f1(int m) {
  if (!m) return 0;
  int res = 0, now = 1;
  for (int i = N - 1; i >= 0; i--) {
    (res += (S.at(i) - '0') * now) %= m;
    (now *= 2) %= m;
  }
  return res;
}

int f2(int n) {
  return n % __builtin_popcount(n);
}

int main() {
  cin >> N >> S;
  int cnt = count(S.begin(), S.end(), '1');
  int mod1 = cnt - 1, mod2 = cnt + 1;
  int res1 = f1(mod1), res2 = f1(mod2);
  for (int i = 0; i < N; i++) {
    int tmp;
    if (S.at(i) == '1') {
      if (cnt == 1) {
        cout << 0 << "\n";
        continue;
      }
      tmp = res1 - mpow(2, N - i - 1, mod1);
      while (tmp < 0) tmp += mod1;
    } else {
      (tmp = res2 + mpow(2, N - i - 1, mod2)) %= mod2;
    }
    int ans = 1;
    while (tmp) tmp = f2(tmp), ans++;
    cout << ans << "\n";
  }
}