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

int main() {
  int n;
  string x;
  cin >> n >> x;
  vector<int> f(n + 1);
  for (int i = 1; i <= n; i++) {
    f.at(i) = f.at(i % __builtin_popcount(i)) + 1;
  }
  int s = count(x.begin(), x.end(), '1'), r0 = 0, r1 = 0;
  vector<int> p0, p1;
  p0.push_back(1);
  p1.push_back(1);
  for (int i = 0; i < n; i++) {
    r0 *= 2;
    r1 *= 2;
    if (x.at(i) == '1') {
      r0++;
      r1++;
    }
    if (s > 1) r0 %= s - 1;
    r1 %= s + 1;
    if (s > 1) p0.push_back(p0.at(i) * 2 % (s - 1));
    p1.push_back(p1.at(i) * 2 % (s + 1));
  }
  for (int i = 0; i < n; i++) {
    if (x.at(i) == '1') {
      if (s > 1) {
        cout << f.at((r0 + (s - 1) - p0.at(n - 1 - i)) % (s - 1)) + 1 << "\n";
      } else {
        cout << 0 << "\n";
      }
    } else {
      cout << f.at((r1 + p1.at(n - 1 - i)) % (s + 1)) + 1 << "\n";
    }
  }
}
