#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int lcm(int a, int b)
{
    return a / __gcd(a, b) * b;
}
int logn(int n, int r)
{
    return log(n) / log(r);
}

int mp[200007];
int pr[200007], pr1[200007];

int getMod(string str, int n, int k)
{
    int pwrTwo[200007];
    pwrTwo[0] = 1 % k;
    for (int i = 1; i < n; i++)
    {
        pwrTwo[i] = pwrTwo[i - 1] * (2 % k);
        pwrTwo[i] %= k;
    }
    int res = 0;
    int i = 0, j = n - 1;
    while (i < n)
    {
        if (str[j] == '1')
        {
            res += (pwrTwo[i]);
            res %= k;
        }
        i++;
        j--;
    }
    return res;
}
void solve()
{
    for (int i = 1; i <= 200005; i++)
    {
        int c = i;
        int ans = 0;
        while (c)
        {
            ans++;
            int p = __builtin_popcount(c);
            c = c % p;
        }

        mp[i] = ans;
    }
    int n;
    cin >> n;
    string s;
    cin >> s;
    int c = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '1')
        {
            c++;
        }
    }
    int f = getMod(s, n, c + 1);
 
    pr[0] = 1 % (c+1);
    for (int i = 1; i < n; i++)
    {
        pr[i] = pr[i - 1] * (2 % (c+1));
        pr[i] %= (c+1);
    }
    if (c == 1)
    {
        int m = n;
        m--;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '1')
            {
                cout << 0 << endl;
            }
            else
            {
                int r = pr[m];
                 
                r %= (c + 1);
                int h = (f + r) % (c + 1);
                if (h < 0)
                {
                    h += (c + 1);
                }
                cout << 1 + mp[h] << endl;
            }
            m--;
        }
        return;
    }
    int g = getMod(s, n, c - 1);
     
    pr1[0] = 1 % (c-1);
    for (int i = 1; i < n; i++)
    {
        pr1[i] = pr1[i - 1] * (2 % (c-1));
        pr1[i] %= (c-1);
    }
    int ans = 0;
    int m = n;
    m--;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '1')
        {
            int r = pr1[m];
            r %= (c - 1);
            int h = (g - r) % (c - 1);
            if (h < 0)
            {
                h += (c - 1);
            }
            cout << 1 + mp[h] << endl;
        }
        else
        {
            int r = pr[m];
            r %= (c + 1);
            int h = (f + r) % (c + 1);
            if (h < 0)
            {
                h += (c + 1);
            }
            cout << 1 + mp[h] << endl;
        }
        m--;
    }
    // m--;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 10096