#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
Vi memo(200050,0);
ll count(ll i){
    if(i==0) return 0;
    if(__builtin_popcount(i)==1){
        return 1;
    }else{
        return 1+count(i%__builtin_popcount(i));
    }
}
void solve(){
    int n;
    cin >> n;
    string x;
    cin >> x;
    ll pc=0;
    rp(i,n){
        if(x[i]=='1')pc++;
    }
    repi(i,1,200030){
        memo[i]=count(i);
    }
    reverse(all(x));
    Vi minus(200050),plus(200050);
    if(pc==0){
        rp(i,n){
            print(1);
        }
        return;
    }
    if(pc==1){
        Vi ans;
        rp(i,n){
            if(i==0){
                if(x[0]=='0'){
                    ans.pb(2);
                }else{
                    ans.pb(0);
                }
                continue;
            }
            if(x[i]=='1'){
                ans.pb(0);
            }else{
                if(x[0]=='0'){
                    ans.pb(1);
                }else{
                    ans.pb(2);
                }
            }
        }
        reverse(all(ans));
        for(auto an:ans){
            print(an);
        }
        return;
    }
    ll cur=1;
    rp(i,200030){
        minus[i]=cur;
        cur=cur*2%(pc-1);
    }
    cur=1;
    rp(i,200030){
        plus[i]=cur;
        cur=cur*2%(pc+1);
    }
    ll p_mod=0;
    ll m_mod=0;
    rp(i,n){
        if(x[i]=='1'){
            p_mod+=plus[i];
            m_mod+=minus[i];
        }
    }
    Vi ans;
    rp(i,n){
        if(x[i]=='1'){
            ll a=(m_mod-minus[i])%(pc-1);
            if(a<0) a+=pc-1;
            ans.pb(memo[a]+1);
        }else{
            ll a=(p_mod+plus[i])%(pc+1);
            ans.pb(memo[a]+1);
        }
    }
    reverse(all(ans));
    for(auto an:ans){
        print(an);
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 10204