Problem:
Score : 400 points

Problem Statement

Let \mathrm{popcount}(n) be the number of 1s in the binary representation of n.
For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.

Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)

For example, when n=7, it becomes 0 after two operations, as follows:

\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.

\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.

You are given an integer X with N digits in binary.
For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted.
Find f(X_1), f(X_2), \ldots, f(X_N).

Constraints

1 \leq N \leq 2 \times 10^5

X is an integer with N digits in binary, possibly with leading zeros.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print N lines. The i-th line should contain the value f(X_i).

Sample Input 1

3
011

Sample Output 1

2
1
1

X_1 = 7, which will change as follows: 7 \rightarrow 1 \rightarrow 0. Thus, f(7) = 2.

X_2 = 1, which will change as follows: 1 \rightarrow 0. Thus, f(1) = 1.

X_3 = 2, which will change as follows: 2 \rightarrow 0. Thus, f(2) = 1.

Sample Input 2

23
00110111001011011001110

Sample Output 2

2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repd(z, x, y) for(int z=y;z>=x;--z)
#define com bool operator<(const node &b)
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int T = 1;
int num1, num2;

int now = 0;
int f[maxn];

void f1(int val) {
    int tmp = (num1 + val) % (now + 1);
    cout << f[tmp] + 1 << '\n';
}

void f2(int val) {
    int tmp = ((num2 + val) % (now - 1) + now - 1) % (now - 1);
    cout << f[tmp] + 1 << '\n';
}

int fac1[maxn];
int fac2[maxn];

void solve() {
    rep(i, 1, 2e5) {
        int t = i;
        int s = __builtin_popcount(t);
        t %= s;
        f[i] = f[t] + 1;
    }
    string s;
    int n;
    cin >> n;
    fac1[0] = fac2[0] = 1;
    cin >> s;
    for (auto &i:s)now += (i == '1');
    if (now == 0) {
        rep(i, 1, n)cout << 1 << '\n';
        return;
    }
    if (now == 1) {
        if (s[s.size() - 1] == '1') {
            rep(i, 1, n - 1)cout << 2 << '\n';
            cout << 0 << '\n';
        } else {
            rep(i, 0, n - 1) {
                if (s[i] == '1')
                    cout << 0 << '\n';
                else
                    cout << 1 << '\n';
            }
        }
        return;
    }
    rep(i, 1, n) {
        fac1[i] = fac1[i - 1] * 2 % (now + 1);
        fac2[i] = fac2[i - 1] * 2 % (now - 1);
    }
    for (auto &i:s) {
        num1 = num1 * 2 + (i == '1');
        num2 = num2 * 2 + (i == '1');
        num1 %= (now + 1);
        num2 %= (now - 1);
    }
    for (int i = 0, j = n - 1; i < n; ++i, --j) {
        if (s[i] == '1')
            f2(-fac2[j]);
        else
            f1(fac1[j]);
    }
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}