#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string B;
    cin >> B;
    ll count=0;
    for(auto p: B){
        if(p=='1')count++;
    }
    ll coup=0,coum=0;
    for(ll i=0;i<N;++i){
        if(B[i]=='1')coup+=modpow(2,N-1-i,count+1);
        coup%=count+1;
    }
    if(count>1)
    for(ll i=0;i<N;++i){
        if(B[i]=='1')coum+=modpow(2,N-1-i,count-1);
        coum%=count-1;
    }

    //1操作後の到達数
    function<ll(ll)> G=[&](ll g){
        ll ret;
        if(B[g]=='1'&&count>1){
            ret = (coum+count-1-modpow(2,N-1-g,count-1))%(count-1);
        }
        else if(B[g]=='0'){
            ret = (coup+modpow(2,N-1-g,count+1))%(count+1);
        }
        else if(count==1&&B[g]=='1')ret=INF;
        return ret;
    };
    function<ll(ll)> F=[&](ll n){
        ll ret=0;
        while(n){
            n%=__builtin_popcountll(n);
            ret++;
        }
        return ret;
    };
    for(ll i=0;i<N;++i){
        ll h=G(i);
        //debug(h)continue;
        if(h==INF)prt(0);
        else 
        prt(1+F(h));
    }fl

    return 0;
}



Measured memory_bytes: 3756