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)

#include<stdio.h>
#include<string.h>
#include<math.h>

#define B_MAX 200001

char in_bit[200002];
int org_bit[200001];//先頭が最下位bit

long long int q_list[200001];//10進数
//int divid_list[200001];//q_listの余りから入れていく
int a_list[200001];//q_listの対

int main()
{
	int n, org_b = 0;
    long long int x = 1, x_p_m = 1, x_m_m = 1, x_p_f = 0, x_m_f = 0;


	scanf("%d", &n);
	scanf("%s", in_bit);

	for (int i = 0; i<n; i++)
	{
		if (in_bit[(n - 1) - i] == '0')
		{
			org_bit[i] = 0;
		}
		else {
			org_bit[i] = 1;
			org_b++;
		}

	}

    for (int i = 0; i<n; i++)
    {
        if (org_bit[i] == 1)
        {
            x_p_f += x_p_m;
            x_m_f += x_m_m;

            q_list[i] = -x_m_m;
        } else {
            q_list[i] = +x_p_m;
        }

        x_p_m *= 2;
        if (x_p_m > B_MAX)
         x_p_m = x_p_m % (org_b + 1);

        x_m_m *= 2;
        if (x_m_m > B_MAX)
        {
            if (org_b != 1)
                x_m_m = x_m_m % (org_b - 1);
            else
                x_m_m = 0;
                a_list[i] = 0;
        }

    }

	for (int i = 0; i<n; i++)
	{
		long long int target;
        int answer = 1, tmp_bit;

		tmp_bit = org_b + 1 - 2 * org_bit[i];

        if (tmp_bit == 0)
        {

            target = 0;
        } else {
            if (org_bit[i] == 0)
            {
                target = ((q_list[i] + x_p_f) % (tmp_bit));
            } else {
                target = ((q_list[i] + x_m_f) % (tmp_bit));
            }

		    answer++;
        }

		while (target != 0)
		{
			int tmp_tmp_bit = 0;
            long long int tmp_tmp_target = target;

			for (; tmp_tmp_target > 0;)
			{
				tmp_tmp_bit += (1)&(tmp_tmp_target);
                tmp_tmp_target = tmp_tmp_target >> 1;
			}

			target = target % tmp_tmp_bit;
			answer++;
			tmp_bit = tmp_tmp_bit;
		}

		a_list[i] = answer;

	}


	for (int i = (n - 1); i >= 0; i--)
	{
		printf("%d\n", a_list[i]);
	}


	return 0;
}