#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int f(int x){
    for(int ans=0;;x%=__builtin_popcount(x),ans++){
        if(x==0)
            return ans;
    }
}
int a[200000],b[200000];
signed main(){
    int n;
    string x;
    cin>>n>>x;
    int popx=count(x.begin(),x.end(),'1');
    if(popx==1){
        if(x.back()=='1'){
            for(int i=0;i<n-1;i++)
                cout<<2<<endl;
            cout<<0<<endl;
        }else{
            for(int i=0;i<n-1;i++)
                cout<<(x[i]=='1'?0:1)<<endl;
            cout<<2<<endl;
        }
      return 0;
    }
    a[n-1]=b[n-1]=1;
    for(int i=n-2;i>=0;i--){
        a[i]=a[i+1]*2%(popx+1);
        b[i]=b[i+1]*2%(popx-1);
    }
    int aa=0,bb=0;
    for(int i=0;i<n;i++){
        if(x[i]=='1'){
            (aa+=a[i])%=popx+1;
            (bb+=b[i])%=popx-1;
        }
    }
    for(int i=0;i<n;i++){
        if(x[i]=='1')
            cout<<f((bb-b[i]+popx-1)%(popx-1))+1<<endl;
        else
            cout<<f((aa+a[i])%(popx+1))+1<<endl;
    }
}
