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

int pcnt(int x){
  return __builtin_popcount(x);
}

int f(int x){
  if(x == 0) return 0;
  else return f(x%pcnt(x))+1;
}

int main() {
  int n,pc = 0;
  string s;
  cin >> n >> s;
  vector<int>x(n);
  vector<int>ans(n);
  rep(i,0,n){
    x[i] = s[i]-'0';
    if(s[i] == '1') pc++;
  }
  rep(b,0,2){
    int npc = pc,r0 = 0;
    if(b == 0) npc++;
    else npc--;
    if(npc <= 0) continue;
    rep(i,0,n){
      r0 = (2*r0)%npc;
      r0 += x[i];
    }
    int k = 1;
    for(int i = n-1;i >= 0;i--){
      int r = r0;
      if(x[i] == b){
        if(b == 0) r = (r+k)%npc;
        else r = (r-k+npc)%npc;
        ans[i] = f(r)+1;
      }
      k = (2*k)%npc;
    }
  }
  rep(i,0,n) cout << ans[i] << endl;
}