#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
//const long long int pl=1000000;

long long int res=0,L[3][200200]={},R[3][200200]={},d,T,a[200200],f[10020]={};
long long int cou=0,two[2][200200]={};
string N;

int main(){

    cout << fixed << setprecision(18);
    cin>>T>>N;
    
    for(long long int i = 0; i <N.size(); i++){
        if(N[i]=='1'){
            cou++;
        }

    }
    two[0][0]=1;
    two[1][0]=1;
    //-1
    for(long long int i = 1; i < N.size(); i++){
        two[0][i]=2*two[0][i-1];
        if(cou!=1){
            two[0][i]%=(cou-1);
        }else{
            two[0][i]=0;
        }
        
    }
    for(long long int i = 0; i < N.size(); i++){
        L[0][i]=(N[N.size()-1-i]-'0')*two[0][i];
        R[0][i]=(N[N.size()-1-i]-'0')*two[0][i];
    }
    for(long long int i = 1; i < N.size(); i++){
        L[0][i]+=L[0][i-1];
    }
    for(long long int i = N.size()-1; i >=1; i--){
        R[0][i-1]+=R[0][i];
    }

    //+1
    for(long long int i = 1; i < N.size(); i++){
        two[1][i]=2*two[1][i-1];
        two[1][i]%=(cou+1);
        
    }
    for(long long int i = 0; i < N.size(); i++){
        L[1][i]=(N[N.size()-1-i]-'0')*two[1][i];
        R[1][i]=(N[N.size()-1-i]-'0')*two[1][i];
    }
    for(long long int i = 1; i < N.size(); i++){
        L[1][i]+=L[1][i-1];
    }
    for(long long int i = N.size()-1; i >=1; i--){
        R[1][i-1]+=R[1][i];
    }

    for(long long int i = 0; i < N.size(); i++){
        
        long long int tmp,restmp=1;
        if(N[i]=='1'){
            if(cou==1){cout<<0<<endl;continue;}
            else{
                if(i!=0&&i!=N.size()-1){
                    tmp=L[0][N.size()-1-i-1]+R[0][N.size()-i];
                }
                else if(i==0){tmp=L[0][N.size()-1-i-1];}
                else{tmp=R[0][N.size()-i];}
            }
            
            //cout<<"-1 "<<i<<" "<<tmp<<" "<<cou<<endl;
            tmp%=(cou-1);
            while(tmp!=0){
                long long int tmpmemo=tmp,md=0;
                while(tmpmemo!=0){
                    if(tmpmemo%2==1){md++;}
                    tmpmemo/=2;
                }
                restmp++;
                if(md==0){break;}
                else{
                    tmp=tmp%md;
                }
            }

            cout<<restmp<<endl;
        }else{
            if(cou==-1){cout<<0<<endl;continue;}
            else{
                if(i!=0&&i!=N.size()-1){tmp=L[1][N.size()-1-i-1]+R[1][N.size()-i];}
                else if(i==0){tmp=L[1][N.size()-1-i-1];}
                else{tmp=R[1][N.size()-i];}
                
                tmp+=two[1][N.size()-1-i];
            }
            
            //cout<<"+1 "<<i<<" "<<tmp<<" "<<cou<<endl;
            tmp%=(cou+1);
            
            while(tmp!=0){
                long long int tmpmemo=tmp,md=0;
                while(tmpmemo!=0){
                    if(tmpmemo%2==1){md++;}
                    tmpmemo/=2;
                }
                restmp++;
                if(md==0){break;}
                else{
                    tmp=tmp%md;
                }
            }

            cout<<restmp<<endl;
        }
        
    }
}



Measured memory_bytes: 13148