Language: C++

#include<bits/stdc++.h> 
using namespace std;
const int N=2e5+5;
int n,mod1,mod2,
int md1[N],md2[N]
int ans1,ans2,temp;
char s[N];
void solve(int n)
{
	while (n>0)
	{
		int q=n,p=0;
		while (q>0)
		{
			q=q&(q-1);
			p++;
		}
		n=n%p;
		temp++;
	}
}
int main()
{
	cin>>n;
	scanf("%s",&s);
	for (int i=0;i<n;i++) if (s[i]=='1') mod1++;
	mod2=mod1-1,mod1++;
	if (mod2==0)
	{
		md1[n-1]=md2[n-1]=1;
		for (int i=n-2;i>=0;i--) md1[i]=md1[i+1]*2%mod1;
		for (int i=n-1;i>=0;i--) if (s[i]=='1') ans1=(ans1+md1[i])%mod1;
		for (int i=0;i<n;i++)
		{
			if (s[i]=='1') cout<<0<<endl;
			if (s[i]=='0')
			{
				temp=1;
				int tmp=(ans1+md1[i])%mod1;
				solve(tmp);
				cout<<temp<<endl;
			}
		}
		return 0;
	}
	md1[n-1]=md2[n-1]=1;
	for (int i=n-2;i>=0;i--) md1[i]=md1[i+1]*2%mod1,md2[i]=md2[i+1]*2%mod2;
	for (int i=n-1;i>=0;i--) if (s[i]=='1') ans1=(ans1+md1[i])%mod1,ans2=(ans2+md2[i])%mod2;
	for (int i=0;i<n;i++)
	{
		if (s[i]=='1')
		{
			temp=1;
			int tmp=(ans2-md2[i]+mod2)%mod2;
			solve(tmp);
			cout<<temp<<endl;
		}
		if (s[i]=='0')
		{
			temp=1;
			int tmp=(ans1+md1[i])%mod1;
			solve(tmp);
			cout<<temp<<endl;
		}
	}
}

Compiler output:
a.cc:5:1: error: expected unqualified-id before 'int'
    5 | int md1[N],md2[N]
      | ^~~
a.cc: In function 'void solve(int)':
a.cc:19:17: error: 'temp' was not declared in this scope; did you mean 'tm'?
   19 |                 temp++;
      |                 ^~~~
      |                 tm
a.cc: In function 'int main()':
a.cc:30:17: error: 'md1' was not declared in this scope; did you mean 'mod1'?
   30 |                 md1[n-1]=md2[n-1]=1;
      |                 ^~~
      |                 mod1
a.cc:30:26: error: 'md2' was not declared in this scope; did you mean 'mod2'?
   30 |                 md1[n-1]=md2[n-1]=1;
      |                          ^~~
      |                          mod2
a.cc:32:57: error: 'ans1' was not declared in this scope
   32 |                 for (int i=n-1;i>=0;i--) if (s[i]=='1') ans1=(ans1+md1[i])%mod1;
      |                                                         ^~~~
a.cc:38:33: error: 'temp' was not declared in this scope; did you mean 'tm'?
   38 |                                 temp=1;
      |                                 ^~~~
      |                                 tm
a.cc:39:42: error: 'ans1' was not declared in this scope
   39 |                                 int tmp=(ans1+md1[i])%mod1;
      |                                          ^~~~
a.cc:46:9: error: 'md1' was not declared in this scope; did you mean 'mod1'?
   46 |         md1[n-1]=md2[n-1]=1;
      |         ^~~
      |         mod1
a.cc:46:18: error: 'md2' was not declared in this scope; did you mean 'mod2'?
   46 |         md1[n-1]=md2[n-1]=1;
      |                  ^~~
      |                  mod2
a.cc:48:49: error: 'ans1' was not declared in this scope
   48 |         for (int i=n-1;i>=0;i--) if (s[i]=='1') ans1=(ans1+md1[i])%mod1,ans2=(ans2+md2[i])%mod2;
      |                                                 ^~~~
a.cc:48:73: error: 'ans2' was not declared in this scope
   48 |         for (int i=n-1;i>=0;i--) if (s[i]=='1') ans1=(ans1+md1[i])%mod1,ans2=(ans2+md2[i])%mod2;
      |                                                                         ^~~~
a.cc:53:25: error: 'temp' was not declared in this scope; did you mean 'tm'?
   53 |                         temp=1;
      |                         ^~~~
      |                         tm
a.cc:54:34: error: 'ans2' was not declared in this scope
   54 |                         int tmp=(ans2-md2[i]+mod2)%mod2;
      |                                  ^~~~
a.cc:60:25: error: 'temp' was not declared in this scope; did you mean 'tm'?
   60 |                         temp=1;
      |                         ^~~~
      |                         tm
a.cc:61:34: error: 'ans1' was not declared in this scope
   61 |                         int tmp=(ans1+md1[i])%mod1;
      |                                  ^~~~