#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383279502884197;
long long MOD;
long long fac[1] = {1}, inv[1] = {1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mp(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
long long cmb(long long r, long long c) {
  return fac[r] * inv[c] % MOD * inv[r - c] % MOD;
}
priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;
int n;
char s[200001];
long long two[200001][3];
int f(int o) {
  if (o == 0) return 0;
  int cnt = __builtin_popcount(o);
  return f(o % cnt) + 1;
}
int main() {
  scanf("%d %s", &n, s);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    s[i] -= '0';
    cnt += s[i];
  }
  for (int j = 0; j < 3; j++) {
    two[0][j] = 1;
    if (j == 0 && cnt == 1) continue;
    for (int i = 1; i < n; i++) two[i][j] = two[i - 1][j] * 2 % (cnt + j - 1);
  }
  int oc = cnt;
  long long now[3] = {0};
  reverse(s, s + n);
  for (int j = 0; j < 3; j++) {
    if (j == 0 && cnt == 1) continue;
    for (int i = n - 1; i >= 0; i--) {
      now[j] = (now[j] + s[i] * two[i][j]) % (cnt + j - 1);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    cnt -= s[i];
    s[i] ^= 1;
    cnt += s[i];
    int j = cnt - oc + 1;
    long long pre = now[j];
    if (cnt == 0)
      printf("%d\n", 0);
    else {
      if (s[i] == 0)
        now[j] = (now[j] - two[i][j] + cnt) % cnt;
      else
        now[j] = (now[j] + two[i][j]) % cnt;
      printf("%d\n", f(now[j]) + 1);
      now[j] = pre;
    }
    cnt -= s[i];
    s[i] ^= 1;
    cnt += s[i];
  }
}
