#include<bits/stdc++.h>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//lower_bound like o_set.find_by_order(val) strictly less then val
//upper_bound like o_set.order_of_key(MAX)– o_set.order_of_key(val)
//if u need multiset elements then use second parameter as time and think 
//typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const int MAX=2e5+5;
const ll MM=1e16;
const ll mod=998244353;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll expo(ll x,ll n,ll M)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}
vector<string> v;
void fun(string s,int index,int last,string a)
{
    if(index==s.length())
    {
        v.pb(a);return;
    }
    if(last==1)
    {
        fun(s,index+1,0,a+s[index]);
        int val=a[a.size()-1]-'0';
        char c='0'+val+1;
        a[a.size()-1]=c;
        fun(s,index+1,1,a);
    }
    else if(last==0)
    {
        fun(s,index+1,0,a+s[index]);
        char c='1';
        a+=c;
        fun(s,index+1,1,a);   
    }
    
    
}

void solve()
{
    ll n,m,i,j,k;
    cin>>n;
    ll num=0;
    string a;
    cin>>a;
    vl v(MAX,0);
    v[1]=1;
    fs(i,2,MAX)
    {
        ll m=setbitsll(i);
        ll val=i%m;
        v[i]=v[val]+1;
    }
    // fn(i,11)cout<<v[i]<<" ";
    // cout<<endl;
    ll count=0;
    fn(i,n)
    if(a[i]=='1')count++;
    map<ll,ll> mp;
    ll val=0;
        if(count>0)
        {
            fr(i,n-1,0)
            {
                if(a[i]=='1')
                val=(val+expo(2,n-1-i,count))%count;
            }
            mp[count]=val;
        }
        else
        {
            mp[count]=0;
        }
    
        if((count-1)>0)
        {
            val=0;
            fr(i,n-1,0)
            {
                if(a[i]=='1')
                val=(val+expo(2,n-1-i,count-1))%(count-1);
            }
            mp[count-1]=val;
        }
        else
        {
            mp[count-1]=0;
        }
        val=0;
        fr(i,n-1,0)
        {
            if(a[i]=='1')
            val=(val+expo(2,n-1-i,count+1))%(count+1);
            // debug2(i,val);
        }
        // debug(val)
        mp[count+1]=val;
    fs(i,0,n)
    {
        if(a[i]=='1')
        {
            ll m=count-1;
            if(m==0)
            cout<<0<<endl;
            else{ 
            // debug2(m,mp[m]);
            ll temp=mp[m]-expo(2,n-1-i,m);
            W(temp<0)temp+=m;
            cout<<v[temp]+1<<endl;
            }
        }
        else
        {
            ll m=count+1;
            if(m==0)
            cout<<0<<endl;
            else{ 
            //  debug2(m,mp[m]);
             ll temp=mp[m]+expo(2,n-1-i,m);
            temp%=m;
            cout<<v[temp]+1<<endl;
            }
        }
        
    }

    
    
}

int main()
{
  boost;
  ll t=1;
//   cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 5204