#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

ll MOD;

ll add(ll x, ll y)
{
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}
ll sub(ll x, ll y)
{
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}
ll mult(ll x, ll y , ll MOD)
{
    return (x * y) % MOD;
}
ll bin_pow(ll x, ll p , ll MOD)
{
    if (p == 0)
        return 1;
    if (p & 1)
        return mult(x, bin_pow(x, p - 1 ,  MOD) ,MOD);
    return bin_pow(mult(x, x ,MOD), p / 2 , MOD);
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    string s;
    cin>>n>>s;
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
        if(s[i]=='1') cnt++;
    }

    if(cnt==0){
        for (int i = 0; i < n; i++)
        {
            cout<<1<<endl;
        }
        return 0;
    }
    if(cnt==1){
        if(s.back()=='0'){
            for (int i = 0; i < n; i++)
            {
                if(s[i]=='0'){
                   if(i!=n-1) cout<<1<<endl;
                   else{
                       cout<<2<<endl;
                   }
                }
                else{
                    cout<<0<<endl;
                }
            }
        }
        else{
            for (int i = 0; i < n; i++)
            {
                if(s[i]=='0'){
                    cout<<2<<endl;
                }
                else{
                    cout<<0<<endl;
                }
            }
            
        }
        return 0;
    }
    int mod1=cnt+1;
    int mod2=cnt-1;
    int sum1=0;
    int sum2=0;
    int r=1;
    
    for (int i = 0; i < n; i++)
    {
        if(s[n-1-i]=='1') {
            sum1+=r;
            sum1%=mod1;
        }
        r*=2;
        r%=mod1;
    }
    r=1;
    for (int i = 0; i < n; i++)
    {
        if(s[n-1-i]=='1') {
            sum2+=r;
            sum2%=mod2;
        }
        r*=2;
        r%=mod2;
    }
    vector<int>v(n);
    vector<int>res(n);
    for (int i = 0; i < n; i++)
    {
        if(s[i]=='1'){
            MOD=mod2;
            int x=sum2 + MOD *10- bin_pow(2 , n-1-i ,MOD);
            x%=MOD;
            v[i]=x;
        }
        else{
            MOD=mod1;
            int x=sum1 + MOD + bin_pow(2 , n-1-i , MOD);
            x%=MOD;
            v[i]=x;
        }
    }
    //cerr<<sum1<<" "<<sum2<<endl;
    //show(v);
    for (int i = 0; i < n; i++)
    {
        int x=v[i];
        if(x==0){
            res[i]=1;
            continue;
        }
        int ans=1;
        while(1){
            int c=0;
            vector<int>tmp;
            for (int i = 0; i < 50; i++)
            {
                if(x & (1LL<<i)) {
                    c++;
                   // tmp.push_back(i);
                }
            }
            x%=c;
            ans++;
            if(x==0){
                res[i]=ans;
                break;
            }
        
            //cerr<<x<<" "<<c<<endl;
            //show(tmp);
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout<<res[i]<<'\n';
    }
    
    

    return 0;
}

Measured memory_bytes: 6772