#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}


int popcount(int n){
    bitset<32> s(n);
    int count = 0;
    for(int i=0;i<32;i++){
        if(s[i]==1){
        count++;
        }
    }

    return count;
}



signed main(){
    int N; cin>>N;
    string X; cin>>X;

    int one_num = 0;
    for(int i=0;i<N;i++){
        if(X.at(i)=='1')one_num++;
    }
    //cout<<one_num<<endl;

    //元の数値を割り算した結果を考える。
    int original_minus=0;
    int original_plus=0;
    int reminder_minus=1;
    int reminder_plus=1;
    int reminders_p[N];
    int reminders_m[N];
    for(int i=0;i<N;i++){
        if(X.at(N-i-1)=='1'){
            if(i==0){
                if(one_num>1){
                    original_minus = reminder_minus%(one_num-1);
                }
                original_plus = reminder_plus%(one_num+1);
            }else{
                //original_amari = (original_amari + prev_amari*2%one_num)%one_num;
                if(one_num>1){
                    original_minus = (original_minus+reminder_minus)%(one_num-1);
                }
                original_plus = (original_plus+reminder_plus)%(one_num+1);
            }
        }
        reminders_p[i] = reminder_plus;
        reminders_m[i] = reminder_minus;
        reminder_plus = (reminder_plus*2)%(one_num+1);
        if(one_num>1){
            reminder_minus = (reminder_minus*2)%(one_num-1);
        }
    }
    //cout<<original_minus<<" "<<original_plus<<endl;

    int answer[N];
    for(int i=0;i<N;i++){
        if(X.at(N-i-1)=='1'){
            // この時には1が反転して0になるので、original_minusのほうを考えないといけない
            if(one_num==1){
                // 最初から0になる例外処理
                answer[N-i-1] = 0;
                continue;
            }
            if(one_num==2){
                // 最初から1になる例外処理
                answer[N-i-1] = 1;
                continue;
            }

            // 最初に割り算したときの値は、
            int temp = original_minus - reminders_m[i];
            if(temp<0) temp+=one_num-1;

            int count = 1;
            if(temp==0){
                answer[N-i-1] = count;
                continue;
            }
            while(temp>0){
                int aa = popcount(temp);
                temp = temp%aa;
                count++;
                if(temp==0){
                  answer[N-i-1] = count;
                  break;
                }
            }
        }else{
            if(one_num==0){
                answer[N-i-1] = 1;
                continue;
            }
            int temp = (original_plus + reminders_p[i])%(one_num+1);
            int count = 1;
            if(temp==0)answer[N-i-1] = count;
            while(temp>0){
                int aa = popcount(temp);
                //cout<<aa<<" "<<temp<<endl;
                temp = temp%aa;
                count++;
                if(temp==0){
                  answer[N-i-1] = count;
                  break;
                }
            }
        }
    }
    for(auto a : answer){
        cout<<a<<endl;
    }
 







    return 0;
}

Measured memory_bytes: 8444