Language: C++

	#include<bits/stdc++.h>
	#define ll unsigned long long int
	#define loop(i,a,b) for(i=a;i<b;i++)
	#define mod 100000007
	#define INF 1000000000000
	#define pb push_back
	#define lim 500001
	using namespace std;

    int main()
    { ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,n;

        cin>>n>>x;
        vector<ll> ans(n,1);
        char x[n+1];
        ll power[30];

        power[0]=1;
        loop(i,0,n)
         if(x[i]=='1') cnt++;

        loop(i,1,30) {if(cnt>1)power1[i]=(power[i-1]*2)%(cnt-1)
        	power2[i]=(power2[i-1]*2)%(cnt+1);}

        ll val1=0,val2=0;
        	loop(i,0,n)
        	{
        		if(cnt>1)
        		val1=(val1+power1[n-i-1])%(cnt-1);
        	val2=(val2+power2[n-i-1])%(cnt+1);
        }


        loop(i,0,n)
        {
        	if(x[i]=='1'){
        		
        		if(cnt>1){
        			ll curr=((val1-power[n-1-i])%(cnt-1)+(cnt-1))%(cnt-1);
        			while(curr){
        				curr=curr%__builtin_popcountll(curr);
        				ans[i]++;
        			}
        			else
        				ans[i]=0;
        		}
        	}

        	else
        	{
        		ll curr=(val2+power[n-1-i])%(cnt+1);
        			while(curr){
        				curr=curr%__builtin_popcountll(curr);
        				ans[i]++;
        			}
        		}}

        		loop(i,0,n)
        		cout<<ans[i]<<endl;

        		return 0;}

        

Compiler output:
a.cc: In function 'int main()':
a.cc:15:17: error: 'x' was not declared in this scope
   15 |         cin>>n>>x;
      |                 ^
a.cc:22:24: error: 'cnt' was not declared in this scope; did you mean 'int'?
   22 |          if(x[i]=='1') cnt++;
      |                        ^~~
      |                        int
a.cc:24:26: error: 'cnt' was not declared in this scope; did you mean 'int'?
   24 |         loop(i,1,30) {if(cnt>1)power1[i]=(power[i-1]*2)%(cnt-1)
      |                          ^~~
      |                          int
a.cc:24:32: error: 'power1' was not declared in this scope; did you mean 'power'?
   24 |         loop(i,1,30) {if(cnt>1)power1[i]=(power[i-1]*2)%(cnt-1)
      |                                ^~~~~~
      |                                power
a.cc:30:28: error: 'cnt' was not declared in this scope; did you mean 'int'?
   30 |                         if(cnt>1)
      |                            ^~~
      |                            int
a.cc:31:36: error: 'power1' was not declared in this scope; did you mean 'power'?
   31 |                         val1=(val1+power1[n-i-1])%(cnt-1);
      |                                    ^~~~~~
      |                                    power
a.cc:32:28: error: 'power2' was not declared in this scope; did you mean 'power'?
   32 |                 val2=(val2+power2[n-i-1])%(cnt+1);
      |                            ^~~~~~
      |                            power
a.cc:32:44: error: 'cnt' was not declared in this scope; did you mean 'int'?
   32 |                 val2=(val2+power2[n-i-1])%(cnt+1);
      |                                            ^~~
      |                                            int
a.cc:40:28: error: 'cnt' was not declared in this scope; did you mean 'int'?
   40 |                         if(cnt>1){
      |                            ^~~
      |                            int
a.cc:46:33: error: expected '}' before 'else'
   46 |                                 else
      |                                 ^~~~
a.cc:40:34: note: to match this '{'
   40 |                         if(cnt>1){
      |                                  ^
a.cc:51:17: error: 'else' without a previous 'if'
   51 |                 else
      |                 ^~~~
a.cc:53:54: error: 'cnt' was not declared in this scope; did you mean 'int'?
   53 |                         ll curr=(val2+power[n-1-i])%(cnt+1);
      |                                                      ^~~
      |                                                      int
a.cc: At global scope:
a.cc:3:29: error: expected unqualified-id before 'for'
    3 |         #define loop(i,a,b) for(i=a;i<b;i++)
      |                             ^~~
a.cc:60:25: note: in expansion of macro 'loop'
   60 |                         loop(i,0,n)
      |                         ^~~~
a.cc:60:30: error: 'i' does not name a type
   60 |                         loop(i,0,n)
      |                              ^
a.cc:3:37: note: in definition of macro 'loop'
    3 |         #define loop(i,a,b) for(i=a;i<b;i++)
      |                                     ^
a.cc:60:30: error: 'i' does not name a type
   60 |                         loop(i,0,n)
      |                              ^
a.cc:3:41: note: in definition of macro 'loop'
    3 |         #define loop(i,a,b) for(i=a;i<b;i++)
      |                                         ^
a.cc:63:25: error: expected unqualified-id before 'return'
   63 |                         return 0;}
      |                         ^~~~~~
a.cc:63:34: error: expected declaration before '}' token
   63 |                         return 0;}
      |                                  ^