#include<bits/stdc++.h>

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

ll ans[1000000]={0};

ll up[200005]={0};
ll down[200005]={0};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    // cin>>test;
    while(test--)
    {
        for(ll i=1;i<=200000;i++)
        {
            ll no1=__builtin_popcountll(i);
            ans[i]=ans[i%no1]+1;
        }

        ll n;
        cin>>n;

        string str;
        cin>>str;

        ll noo=0;

        for(ll i=0;i<n;i++)
        {
            if(str[i]=='1')
            noo++;
        }

        if(noo==0)
        {
            for(ll i=0;i<n;i++)
            cout<<1<<endl;
            continue;
        }
        else if(noo==1)
        {
            if(str[n-1]=='1')
            {
                for(ll i=0;i<n;i++)
                {
                    if(i!=n-1)
                    cout<<2<<endl;
                    else
                    cout<<0<<endl;
                }
            }
            else
            {
                for(ll i=0;i<n;i++)
                {
                    if(str[i]=='1')
                    cout<<0<<endl;
                    else if(i!=n-1)
                    cout<<1<<endl;
                    else
                    cout<<2<<endl;
                }
            }

            continue;
        }

        ll ku=noo+1;
        ll kd=noo-1;

        for(ll i=0;i<n;i++)
        {
            if(str[i]=='1')
            {
                up[i]=MPOW(2,n-1-i,ku);
                down[i]=MPOW(2,n-1-i,kd);
            }
        }

        ll sumup=0,sumdown=0;

        for(ll i=0;i<n;i++)
        {
            sumup+=up[i];
            sumup%=ku;
            sumdown+=down[i];
            sumdown%=kd;
        }

        for(ll i=0;i<n;i++)
        {
            if(str[i]=='0')
            {
                ll tans=sumup;
                tans+=(MPOW(2,n-1-i,ku));
                tans%=ku;
                cout<<ans[tans]+1<<endl;
            }
            else
            {
                ll tans=sumdown;
                tans-=(MPOW(2,n-1-i,kd));
                tans+=kd;
                tans%=kd;
                cout<<ans[tans]+1<<endl;
            }
            
        }

    }
}

Measured memory_bytes: 8428