#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll n;
    string x;
    cin>>n>>x;
    ll f[200010]={};
    ll cnt=0;
    rep(i,n){
        if(x[i]=='1') cnt++;
    }
    rep2(i,1,n+1){
        ll j=i;
        ll sum=0;
        while(j>0){
            sum+=j%2;
            j/=2;
        }
        if(i%sum==0) f[i]=1;
        else f[i]=f[i%sum]+1;
    }
    ll r0[200010]={},r1[200010]={},r2[200010]={};
    ll now1=1,now2=1;
    rep(i,n){
        // r0[i]=now%cnt;
        r1[i]=now1%(cnt+1);
        if(cnt>1){
            r2[i]=now2%(cnt-1);
        }
        now1*=2;now1%=(cnt+1);
        if(cnt>1){
            now2*=2;
            now2%=(cnt-1);
        }
    }
    ll sum0=0,sum1=0,sum2=0;
    rep(i,n){
        if(x[i]=='1'){
            // sum0+=(r0[n-1-i]);
            // sum0%=cnt;
            sum1+=(r1[n-1-i]);
            sum1%=(cnt+1);
            if(cnt>1){
                sum2+=(r2[n-1-i]);
                sum2%=(cnt-1);
            }
        }
    }
    rep(i,n){
        if(x[i]=='0'){
            ll a=sum1;
            a+=(r1[n-1-i]);
            a%=(cnt+1);
            cout<<1+f[a]<<endl;
        }
        else{
            if(cnt==1){
                cout<<0<<endl;
                continue;
            }
            ll a=sum2;
            a+=(cnt-1);
            a-=(r2[n-1-i]);
            a%=(cnt-1);
            cout<<1+f[a]<<endl;
        }
    }



    




}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve(); 


    return 0;
}


Measured memory_bytes: 8388