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# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramD a = new ProgramD();
            a.main();//実行する

        }

    }
    //ABC170
    class ProgramA
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int h = int.Parse(s[0]);
            int w = int.Parse(s[1]);
            int k = int.Parse(s[2]);

            int count = 0;
            for(int i = h;i <= w;i++)
            {
                if (i % k == 0)
                    count++;
            }

            Console.WriteLine(count);

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int count = 0;
            for(int i = 0; i < n;i = i + 2)
            {
                if (int.Parse(s[i]) % 2 == 1)
                    count++;
            }

            Console.WriteLine(count);

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            int n = int.Parse(Console.ReadLine());

            int[] ans = new int[n];

            for(int x = 1;x <= 100;x++)
                for (int y = 1; y <= 100; y++)
                    for (int z = 1; z <= 100; z++)
                    {
                        long temp = x * x + y * y + z * z + x * y + x * z + y * z;
                        if (temp <= n)
                            ans[temp - 1]++;
                    }

            for(int i = 0;i < n;i++)
                Console.WriteLine(ans[i]);



        }
    }

    class ProgramD
    {
        public void main()
        {

            //入力
            long n = long.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            int count = 0;
            long num = 0;
            long num2 = 0;
            for (int i = 0; i < n; i++)
            {
                if (s[i] == '1')
                    count++;
            }

            if (count == 0)
            {
                for (int i = 0; i < n; i++)
                    Console.WriteLine("1");
                return;
            }

            if (count == 1)
            {
                if (s[(int)n - 1] == '1')
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (i == n - 1)
                            Console.WriteLine("0");
                        else
                            Console.WriteLine("2");
                    }
                }
                else
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (s[i] == '1')
                            Console.WriteLine("0");
                        else if(i == n -1)
                            Console.WriteLine("2");
                        else
                            Console.WriteLine("1");
                    }
                }
                return;
            }

            for (int i = 0; i < n; i++)
            {
                if (s[i] == '1')
                {
                    num += modpow(2, n - 1 - i, count -1);
                    num2 += modpow(2, n - 1 - i, count + 1);
                }
            }

            for (int i = 0; i < n; i++)
            {
                long temp = 0;

                if (s[i] == '1')
                {
                    temp = num;
                    temp -= modpow(2, n - 1 - i, count - 1);
                    temp %= count - 1;
                }
                else
                {
                    temp = num2;
                    temp += modpow(2, n - 1 - i, count + 1);
                    temp %= count + 1;
                }

                long ans = 1;

                while(temp != 0)
                {
                    long t = 0;
                    long t2 = temp;
                    while (temp != 0)
                    {
                        t += temp % 2;
                        temp /= 2;
                    }

                    temp = t2 % t;
                    ans++;

                }

                Console.WriteLine(ans);
            }

        }

        static long modpow(long a, long n, long MOD)
        {
            if (n == 0)
                return 1;
            if (n % 2 == 0)
            {
                long temp = modpow(a, n / 2, MOD);
                return temp * temp % MOD;
            }

            return a * modpow(a, n - 1, MOD) % MOD;
        }
    }

    class ProgramE
    {

        public void main()
        {
            //入力
            string[] t = Console.ReadLine().Split(' ');
            int n = int.Parse(t[0]);
            int k = int.Parse(t[1]);
            string[] s = Console.ReadLine().Split(' ');
            long[] a = new long[n];

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(s[i]);

            long MOD = 1000000000 + 7;

            Array.Sort(a);

            //0,-,+の数を数える
            long minus = 0;
            long plus = 0;
            long zero = 0;

            for (int i = 0; i < n;i++)
            {
                if (a[i] < 0)
                    minus++;
                else if (a[i] == 0)
                    zero++;
                else
                    plus++;
            }

            //もしゼロが必ず含まれるならゼロ
            if (n - zero < k)
            {
                Console.WriteLine("0");
                return;
            }

            if (k % 2 == 1 && zero > 0 && plus == 0)
            {
                Console.WriteLine("0");
                return;
            }

            //マイナスのみ
            if (plus == 0)
            {
                long ans = 1;
                if(k % 2 == 0)
                {
                    for (int i = 0; i < k; i++)
                    {
                        ans *= a[i];
                        ans %= MOD;
                    }
                }
                else
                {
                    for (int i = 0; i < k; i++)
                    {
                        ans *= a[minus - 1 - i];
                        ans %= MOD;
                    }

                }

                if (ans < 0)
                    ans += MOD;

                Console.WriteLine(ans);
                return;
            }

            //プラスのみ
            if (minus == 0)
            {
                long ans = 1;
                for (int i = 0; i < k; i++)
                {
                    ans *= a[n - 1 - i];
                    ans %= MOD;
                }
                
                Console.WriteLine(ans);
                return;
            }

            //プラスだけでもどうにかなるとき
            if (k <= plus)
            {
                int num_m = 0;
                for (int i = 0; i < k; i++)
                {
                    if (a[n - 1 - k + i] < Math.Abs(a[i]))
                        num_m++;
                }

                if (num_m % 2 == 1)
                    num_m--;

                long ans = 1;
                for (int i = 0; i < num_m; i++)
                {
                    ans *= a[i];
                    ans %= MOD;
                }

                for (int i = 0; i < k - num_m; i++)
                {
                    ans *= a[n - 1 -i];
                    ans %= MOD;
                }

                Console.WriteLine(ans);
                return;

            }

            //プラスマイナス混合で考えるとき
            if (k > plus)
            {
                long num_m = k - plus;
                long num_p =plus;

                if (num_m % 2 == 1)
                {
                    num_m++;
                    num_p--;

                }
                long tp = num_p;
                long tm = num_m;
                for (int i = 0;i < tp;i++)
                {
                    if (i + tm > minus)
                        break;

                    if (a[n - 1 - tp + i] < Math.Abs(a[i + tm]))
                    {
                        num_m++;
                        num_p--;
                    }
                    
                }

                if(num_m % 2 == 1)
                {
                    num_m--;
                    num_p++;
                }

                long ans = 1;
                for (int i = 0; i < num_m; i++)
                {
                    ans *= a[i];
                    ans %= MOD;
                }

                for (int i = 0; i < num_p; i++)
                {
                    ans *= a[n - 1 - i];
                    ans %= MOD;
                }

                if (ans < 0)
                    ans += MOD;


                Console.WriteLine(ans);
                return;

            }







        }


    }

}