#include <bits/stdc++.h>

// definitions
#define __Imperial_Lord__ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c <<endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<endl
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<endl
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;

template <class ...Args>
istream &read_args(Args &...args) {return (cin >> ... >> args);}
#define read(...)   __VA_ARGS__; read_args(__VA_ARGS__)

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>    ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}

ll pl(ll a, ll b, ll md)
{
    ll v=a+b;
    while(v<0) v+=md;
    while(v>=md) v-=md;

    return v;
}

ll modexp(ll x, ll ex, ll md) 
{
    ll ans = 1ll;
    while (ex > 0) 
    {
        if (ex & 1ll) ans = (ans * x)%md;
        ex >>= 1ll;
        x = (x * x)%md;
    }
    return ans;
}

// code beigns in main
int main()
{
    __Imperial_Lord__
    ll t=1;
    // cin >> t;

    while(t--)
    {
        ll read(n);
        string read(s);

        ll cnt=0;
        rep(i,0,n) if(s[i]=='1') cnt++;

        if(cnt==0)
        {
            rep(i,0,n)
            p1(1);
            return 0;
        }

        ll a1=0,a2=0;
        rep(i,0,n)
        {   
            if(s[i]=='1')
            {
                if(cnt>1)
                    a1=pl(a1,modexp(2,n-i-1,cnt-1),cnt-1); 
                a2=pl(a2,modexp(2,n-i-1,cnt+1),cnt+1);               
            }
        }

        rep(i,0,n)
        {
            if(s[i]=='1')
            {
                if(cnt==1)
                {
                    p1(0); continue;
                }

                ll l1=pl(a1,-modexp(2,n-i-1,cnt-1),cnt-1);
                while(l1<0) l1+=cnt-1;
                ll ans=1;
                while(l1)
                {
                    ans++;
                    l1%=(high(l1));
                }
                p1(ans);
            }
            else
            {
                ll l1=pl(a2,modexp(2,n-i-1,cnt+1),cnt+1);
                ll ans=1;
                while(l1)
                {
                    ans++;
                    l1%=(high(l1));
                }
                p1(ans);
            }
        }
    }   
    exec;
}

Measured memory_bytes: 3960