#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int f(int a) {
  if (a == 0) return 0;
  return f(a % __builtin_popcount(a)) + 1;
}

int main() {
  int n;
  string x_;
  cin >> n >> x_;
  vector<int> x(n);
  int pc_ = 0;
  rep(i, n) {
    x[i] = x_[i] - '0';
    pc_ += x[i];
  }
  vector<int> ans(n);
  rep(j, 2) {
    int pc = pc_ + (j == 0 ? 1 : -1);
    if (pc == 0) continue;
    int xmod = 0;
    rep(i, n) xmod = (xmod * 2 + x[i]) % pc;
    int powmod = 1;
    for (int i = n - 1; i >= 0; i--) {
      if (x[i] == j) {
        ans[i] = f((xmod + (j == 0 ? powmod : -powmod) + pc) % pc) + 1;
      }
      powmod = (powmod * 2) % pc;
    }
  }
  rep(i, n) cout << ans[i] << endl;
  return 0;
}