//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
ll binpow(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n&1)res=res*x;
         x=x*x;
         n>>=1;
    }
    return res;
}
ll modularExponentiation(ll x,ll n,ll M)
{   
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
        return result;
}
void solve()
{
    ll d1,d2,N,i,o=0,x1=0,x2=0;cin>>N;
    string X;cin>>X;
    fo(i,0,N)if(X[i]=='1')o++;
    d1=o+1;
    d2=o-1;
   // cout<<d1<<" "<<d2<<"\n";
    int pw=1;
    for(i=N-1;i>=0;i--)
    {
        if(X[i]=='1')
        {
            x1=(x1+pw)%d1;
        }
        pw*=2;
        pw%=d1;
    }
    if(d2>0)
    {
        pw=1;
        for(i=N-1;i>=0;i--)
       {
         if(X[i]=='1')
         {
            x2=(x2+pw)%d2;
         }
        pw*=2;
        pw%=d2;
      }
    }
    
    fo(i,0,N)
    {
        int cnt=1;
        if(X[i]=='0')
        {
            int pw=modularExponentiation(2,N-1-i,d1);
            int nw=0;
            nw=(x1+pw)%d1;
            int nm=d1;
            while(nw!=0)
            {
                nm=__builtin_popcount(nw);
                nw%=nm;
                cnt++;
            }
        }
        else
        {
            if(d2>0)
            {
                int pw=modularExponentiation(2,N-1-i,d2);
                int nw=0;
                nw=(x2-pw+d2)%d2;
                int nm=d2;
                while(nw!=0)
                {
                 nm=__builtin_popcount(nw);
                 nw%=nm;
                 cnt++;
               }
            }
            else cnt=0;
        }
        cout<<cnt<<"\n";
    }
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3760