#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

ll modP(ll x, ll y, ll MOD)
{
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}

ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}
ll weight(ll n)
{
    ll ans = 0;
    while (n)
    {
        ll x = n;
        ll cnt = 0;
        while (x)
        {
            cnt++;
            x &= (x - 1);
        }

        //  trace(n, cnt);
        n %= cnt;
        ans++;
    }
    return ans;

}
void value_of_string(string s, ll x)
{
    if (s[x] == '1') s[x] = '0';
    else
        s[x] = '1';

    reverse(all(s));

    ll n = s.size();
    ll ans = 0;
    ll cur = 1;
    ll one = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '1')
        {   ans += (cur);
            one++;
        }
        cur *= 2;
    }
    trace(ans, ans % one, one);
}

void value_of_string(string s)
{
    reverse(all(s));

    ll n = s.size();
    ll ans = 0;
    ll cur = 1;
    ll one = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '1')
        {   ans += (cur);
            one++;
        }
        cur *= 2;
    }
    trace(ans, ans % (one + 1), one + 1);
}
void solve()
{
    ll ans = 0;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll one = 0;
    for (char ch : s)
        if (ch == '1')
            one++;
    ll gone = one + 1, lone = one - 1;
    vector<ll> req_mod(3, 0);
    req_mod[0] = one;
    req_mod[1] = gone;
    req_mod[2] = lone;


    for (int i = 0; i < 3; i++)
        if (req_mod[i] <= 0)
            req_mod[i] = gone + 1;
    vector<vector<ll>> suf(n, vector<ll>(3, 0));
    for (int i = n - 1; i >= 0; i--)
    {

        if (i == n - 1)
        {

            for (int j = 0; j < 3; j++)
                if (s[i] == '1')
                    suf[i][j] = 1 % req_mod[j];
        }
        else
        {

            for (int j = 0; j < 3; j++)
                if (s[i] == '1')
                    suf[i][j] = (suf[i + 1][j] + modP(2, n - i - 1, req_mod[j])) % req_mod[j];
                else
                    suf[i][j] = (suf[i + 1][j]);
        }
    }
    ll cur;
    ll t1;
    for (int i = 0; i < n; i++)
    {
        ans = 0;
        if (s[i] == '0')
        {
            cur = one + 1;
        }
        else
        {
            if (one == 1)
            {
                cout << 0 << "\n";
                continue;
            }
            cur = one - 1;
        }
        ll index = -1;

        for (int j = 0; j < 3; j++)
        {
            if (req_mod[j] == cur)
            {
                index = j;
                break;
            }
        }
        ll temp;
        if (s[i] == '0')
        {
            temp = modP(2, n - i - 1, req_mod[index]);
            t1 = (suf[0][index] + temp) % req_mod[index];
            //     trace(req_mod[index], t1, suf[0][index]);   value_of_string(s, i); value_of_string(s);
            ans = 1;
            ans += weight(t1);
        }
        else
        {
            if (one == 1)
            {
                cout << 0 << "\n";
                continue;
            }
            temp = modP(2, n - i - 1, req_mod[index]);

            t1 = (suf[0][index] - temp + req_mod[index]) % req_mod[index];
            ans = 1;
            ans += weight(t1);
        }


        cout << ans << "\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t ;
    t = 1;
    //  cin >> t;
    while (t--)
        solve();
    return 0;
}





Measured memory_bytes: 14408