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: Runtime Error)

      #include<bits/stdc++.h>
      using namespace std;
      #include <ext/pb_ds/assoc_container.hpp>
      #include <ext/pb_ds/tree_policy.hpp>
      using namespace __gnu_pbds;
      #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
      #define ll long long
      #define int long long
      #define ld long double
      #define pb push_back
      #define f(i,a,b) for(int i=a;i<b;i++)
      #define fd(i,a,b) for(int i=a-1;i>=b;i--)
      #define pf push_front
      #define ppf pop_front
      #define ppb pop_back
      #define fi first
      #define se second
      #define vi vector<int>
      #define pii pair<int,int>
      #define mii map<int,int>
      #define sunn(a,n) f(i,0,n)cin>>a[i];
      #define bol(a,n) f(i,0,n){cout<<a[i]<<" ";}
      #define ashow(a)  for(auto i:a)cout<<i<<" ";
      #define khtm     cout<<endl;
      #define convert  cout<<fixed<<setprecision(x)
      #define all(s) s.begin(),s.end()
      #define len(a) a.length()
      #define INF 1e18
      #define MAXN 2000009
      #define PMOD 998244353
      const double pi=3.14159265358979323;
      const int mod=1e9+7;
      void btao(int n){
        if(n)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
      }
      bool isPrime(int n) 
  { 
      // Corner cases 
      if (n <= 1) 
          return false; 
      if (n <= 3) 
          return true; 
    
      // This is checked so that we can skip 
      // middle five numbers in below loop 
      if (n % 2 == 0 || n % 3 == 0) 
          return false; 
    
      for (int i = 5; i * i <= n; i = i + 6) 
          if (n % i == 0 || n % (i + 2) == 0) 
              return false; 
    
      return true; 
  } 
  int spf[MAXN];
  void sieve()
        {
            spf[1] = 1;
            for (int i=2; i<MAXN; i++)
                spf[i] = i;
            for (int i=4; i<MAXN; i+=2)
                spf[i] = 2;
            for (int i=3; i*i<MAXN; i++)
            {
                if (spf[i] == i)
                {
                    for (int j=i*i; j<MAXN; j+=i)
                        if (spf[j]==j)
                            spf[j] = i;
                }
            }
        }
 
  int lcm(int a,int b){
      return a*b/__gcd(a,b);
  }
int lexo(string s,string t,int n){
  for(int i=0;i<n;i++)
  if(s[i]<t[i])return 1;
  return 0;
}
int  binpow(int  a,int  b) 
{
    int res = 1;
    while (b > 0) {
        if (b%2 == 1)
            res = (res * a)%mod;
        a = (a* a)% mod;
        b >>= 1;
    }
    return res;
}
int modinv(int y)
{
    return binpow(y,mod-2);
}
 
int fact[500000+5];
void precal()
{
    fact[0]=1;
    for(int i=1;i<500000+5;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
}
int pcnt(int bit[],int k)
{   
    int n=0;
    int c=0,x=0;
    
    while(1)
    {   n=0,x=0;
        for(int i=0;i<k;i++)
        {
            n+=bit[i]*pow(2,i);
            if(bit[i]==1)x++;
        }
        n=n%x;
        c++;
        if(n==0)break;
        bitset<32>b(n);
        for(int i=0;i<k;i++)
            bit[i]=b[i];
        
    }
    return c;
}
       signed main() {

          ios_base::sync_with_stdio(false);
          cin.tie(NULL);  
          cout.tie(0);  
       // -------------------------------------Code starts here--------------------------------------------------------------------- 
      int t=1;
      //cin>>t;
      while(t--)
      {
        

           int x=0,y=0;
          int mx=1,mi=INF,mn=INF;
            int tb,ta,tm=0;
            int n,k,m;
            int k0=0,k2=0,k1=0;
         cin>>n;
         string s;
        cin>>s;
        k=len(s);
        int bit[64]={},a[64]={};
        for(int i=k-1;i>=0;i--)
            if(s[i]=='1')bit[k-1-i]=1,a[k-1-i]=1;

        for(int i=k-1;i>=0;i--)
        {
            if(bit[i]==1)a[i]=0;
            else a[i]=1;
            cout<<pcnt(a,k)<<endl;
            f(j,0,k)
            {
                a[j]=bit[j];
            }

        }




         
           
           
                    
   }
}