#include <bits/stdc++.h>

//{{{
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
 vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x;
 while (getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
 template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}
//

int T;
const int N = 2e5 + 10;
int n;

int fun(int x)
{
    int ret = 0;
    while (x)
    {
        int cc = __builtin_popcount(x);
        x %= cc;
        ret++;
    }
    return ret;
}

char s[N];
int c;
int m0[N], m1[N];

// LL power_mod(LL a, LL p, LL mod)
//{
// LL r = 1;
// while (p)
//{
// if (p & 1) r = r * a % mod
// a = product_mod(a, a, mod);
// p >>= 1;
//}
// return r;
//}

int a[N];

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    a[0] = 0;
    for (int i = 1; i <= 200000 + 5; i++)
    {
        a[i] = fun(i);
    }

    // for (int i = 0; i <= 10; i++)
    //{
    // debug(i, a[i]);
    //}

    while (~scanf("%d", &n))
    {
        scanf("%s", s);
        c = 0;
        for (int i = 0; i < n; i++)
            if (s[i] == '1') c++;

        // debug(c);

        if (c == 0)
        {
            for (int i = 0; i < n; i++) cout << 1 << endl;
            continue;
        }

        if (c == 1)
        {
            for (int i = 0; i < n; i++)
            {
                if (i == n - 1)
                {
                    if (s[i] == '1')
                        cout << 0 << endl;
                    else
                        cout << 2 << endl;
                }
                else
                {
                    if (s[i] == '1')
                        cout << 0 << endl;

                    else
                    {
                        if (s[n - 1] == '1')
                            cout << 2 << endl;
                        else
                            cout << 1 << endl;
                    }
                }
            }
            continue;
        }

        m0[0] = 1 % (c - 1);
        m1[0] = 1 % (c + 1);
        for (int i = 1; i < n; i++)
        {
            m0[i] = m0[i - 1] * 2 % (c - 1);
            m1[i] = m1[i - 1] * 2 % (c + 1);
        }

        LL val0 = 0, val1 = 0;
        for (int i = 0; i < n; i++)
        {
            int p = n - 1 - i;
            if (s[i] == '1')
            {
                LL v0 = m0[p];
                LL v1 = m1[p];
                val0 = (val0 + v0) % (c - 1);
                val1 = (val1 + v1) % (c + 1);
            }
        }
        // debug(val0, val1);

        for (int i = 0; i < n; i++)
        {
            int p = n - i - 1;
            LL cur;
            if (s[i] == '0')
            {
                cur = val1;
                cur = (cur + m1[p]) % (c + 1);
            }
            else
            {
                cur = val0;
                cur = cur - m0[p];
                if (cur < 0) cur += (c - 1);
            }
            LL ans = a[cur] + 1;
            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 6232