#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define vi vector<long long>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less   
using namespace __gnu_pbds;  
using namespace std;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> set1;
ll mod=1000000007;
ll large=1e18;
ll neg=-1e18;
ll N=500000;
ll mod1=998244353;
struct pii
{
   ll x;
   ll y;
};
struct edge
{
   ll from;
   ll to;
   ll w;
   ll id;
};
ll find(ll a,ll p[])
{
   //cout<<"find "<<a<<endl;
   if(a==p[a])
   return a;
   else return p[a]=find(p[a],p);

}
void join(ll a,ll b,ll p[],ll sz[])
{
   a=find(a,p);
   b=find(b,p);
   if(a!=b)
   {
      if(sz[a]<sz[b])
      swap(a,b);
      sz[a]+=sz[b];
      p[b]=a;
   }
}
ll power(ll a,ll b,ll mod)
{
   ll res=1;
   while(b>0)
   {
      if(b&1)
      res=(res*a)%mod;
      b=b/2;
      a=(a*a)%mod;
   }
   return res;
}
ll inverse(ll x, ll p)
{
   return power(x,p-2,p);
}
ll hash1(ll x,ll y)
{
   return x+y+x*y;
}
/*ll f[200000]={0};

void ini()
{
   f[0]=1;
   for(ll i=1;i<=200000;i++)
   f[i]=(i*f[i-1])%mod;
}*/
void build(ll tree[],ll v,ll l,ll r,ll dp[])
{
   if(l==r)
      tree[v]=dp[l];
   else
   {
      ll m=(l+r)/2;
      build(tree,2*v,l,m,dp);
      build(tree,2*v+1,m+1,r,dp);
      tree[v]=max(tree[2*v],tree[2*v+1]);
   }
}
ll query(ll tree[],ll v,ll l,ll r,ll tl,ll tr)
{
   if(l==tl && tr==r)
   {
    //  cout<<"max of "<<tl<<" "<<tr<<" "<<tree[v]<<endl;
      return tree[v];
   }
   else
   {
      ll m=(l+r)/2;
      if(tr<=m)
      {
         ll z1= query(tree,2*v,l,m,tl,tr);
     //    cout<<"max of "<<tl<<" "<<tr<<" "<<z1<<endl;
         return z1;
      }
      else if(tl>m)
      {
         ll z2= query(tree,2*v+1,m+1,r,tl,tr);
      //   cout<<"max of "<<tl<<" "<<tr<<" "<<z2<<endl;
         return z2;
      }
      else 
      {
         ll z=query(tree,2*v,l,m,tl,m);
         ll z1=query(tree,2*v+1,m+1,r,m+1,tr);
       //  cout<<"max of "<<tl<<" "<<tr<<" "<<max(z1,z)<<endl;
         return max(z1,z);
      }
      
      
   }
}
void update(ll tree[],ll v,ll l,ll r,ll pos,ll element)
{
   if(l==r && l==pos)
   tree[v]=element;
   else
   {
      ll m=(l+r)/2;
      if(pos<=m)
      update(tree,2*v,l,m,pos,element);
      else
      update(tree,2*v+1,m+1,r,pos,element);
      tree[v]=max(tree[2*v],tree[2*v+1]);
   }
}

/*ll ncr(ll n,ll r)
{
   ll res=1;
   ll k=f[n];
   ll v=inverse(f[n-r],mod);
   ll u=inverse(f[r],mod);
   ll x=(u*v)%mod;
   k=(k*x)%mod;
   return k;
}*/
ll max_n=1e6+100;
ll hash2(ll x,ll y,ll W)
{
   return (x-1)*W+y;
}
pii rev(ll u,ll W)
{
   pii ans;
   if(u%W==0)
   {
      ans.y=W;
      ans.x=(u-W)/W+1;
   }
   return ans;

}
ll MAX_N=200000;
string tobin(ll a,ll sz)
{
   string s;
   ll r=0;
   while(a>0)
   {
      if(a%2==0)
      s.pb('0');
      else
      s.pb('1');
      a/=2;
      r++;
   }
   while(r<sz)
   {
      s.pb('0');
      r++;
   }
   reverse(s.begin(),s.end());
   return s;
}
ll tolong(string s)
{
   ll sz=s.size();
   ll ans=0;
   for(ll i=0;i<sz;i++)
   {
      if(s.at(i)=='1')
      ans+=(ll)pow(2,sz-i-1);
      
   }
   return ans;
}
void printvec(vector<ll> &c)
{
   for(ll i : c)
   cout<<i<<" ";
   cout<<endl;
}
void printarr(ll a[],ll n)
{
   for(ll i=0;i<n;i++)
   cout<<a[i]<<" ";
   cout<<endl;
}

int main()
{
  
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll n;
   cin>>n;
   string s;
   cin>>s;
   ll pop=0;
   for(ll i=0;i<n;i++)
   {
      if(s.at(i)=='1')
      pop++;
   }
   ll neg=0;
   ll pos=0;
   ll pp=0;
   if(pop>1)
   {
      //ll act=0;
   for(ll j=n-1;j>=0;j--)
   {
      if(s.at(j)=='1')
      {
         ll pp=n-1-j;
         ll u=power(2,pp,pop+1);
         ll v=power(2,pp,pop-1);
         pos=(pos+u)%(pop+1);
         neg=(neg+v)%(pop-1);
    //     act=act+(ll)pow(2,pp);
      }
     // pp++;
   }
  //cout<<"act "<<act<<endl;
  // cout<<pop<<" pop "<<endl;
   //l h=act%(pop-1);
   //cout<<h<<" check "<<neg<<endl;
   ll ans[n]={0};
   //ll act=0;
  // ll real[n];
   for(ll i=n-1;i>=0;i--)
   {
      if(s.at(i)=='1')
      {
         ll exp=n-1-i;
         ll v=power(2,exp,pop-1);
         ans[i]=neg-v;
         if(ans[i]<0)
         {
            ans[i]=(ans[i]+pop-1)%(pop-1);
         }
         //real[i]=act-(ll)pow(2,exp);
      }
      else
      {
         if(s.at(i)=='0')
         {
            ll exp=n-1-i;
            ll v=power(2,exp,pop+1);
            ans[i]=(pos+v)%(pop+1);
        //    real[i]=act+(ll)pow(2,exp);
         }
      }
   }
   //cout<<"Real valuse "<<endl;
   //printarr(real,n);
   //cout<<endl;
   /*for(ll i=0;i<n;i++)
   {
     // ll z;
      if(s.at(i)=='0')
      z=(real[i])%(pop+1);
      else
      z=real[i]%(pop-1);
      ll u;
       if(s.at(i)=='1')
       u=1;
       else
       u=0;
      cout<<ans[i]<<" real "<<z<<" u "<<u<<endl;
   }*/
   ll cnt[n];
   for(ll i=0;i<n;i++)
   cnt[i]=1;
   for(ll i=0;i<n;i++)
   {
      while(ans[i]!=0)
      {
         ll z=__builtin_popcountll(ans[i]);
         ans[i]=(ans[i]%z);
         cnt[i]++;
      }
   }
   for(ll i=0;i<n;i++)
   cout<<cnt[i]<<endl;
   }
   else if(pop==0)
   {
    for(ll i=0;i<n;i++)
    cout<<1<<endl;

   }
   else if(pop==1)
   {
      ll cnt[n];
      ll k;
      for(ll i=0;i<n;i++)
      {
         if(s.at(i)=='1')
         {
            cnt[i]=0;
            k=i;
            break;
         }
         

      }
      if(k==n-1)
      {
         for(ll i=0;i<k;i++)
         cnt[i]=2;
      }
      else
      {
         for(ll i=0;i<n-1;i++)
         {
            if(i!=k)
            cnt[i]=1;
         }
         cnt[n-1]=2;
      }
      for(ll i=0;i<n;i++)
      cout<<cnt[i]<<endl;

   }
   return 0;
}


Measured memory_bytes: 6920