Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(var) (var).begin(), (var).end()
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >


int power(int x, int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)
        {
            res = (res*x) % p;  
        }  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
int cnt[200005];

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n,i,j,k,x,y;

	cnt[0] = 0;
	cnt[1] = 1;
	cnt[2] = 1;
	for(i=3;i<=200002;i++)
	{	
		x = i;
		y = 0;
		while(x)
		{
			if(x & 1)
			{
				y++;
			}
			x /= 2;
		}
		cnt[i] = 1 + cnt[i % y];
	}
		
	cin >> n;
	string s;
	cin >> s;
	x = 0;
	for(i=0;i<n;i++)
	{
		if(s[i] == '1')
		{
			x++;
		}
	}	

	int ca1= 0, ca2=0;
	for(i=n-1,j=1,k=1;i>=0;i--)
	{
		if(s[i] == '1')
		{
			ca1 += j;
			ca2 += k;
			ca1 %= max(1, (x-1));
			ca1 %= (x+1);
		}
		j *= 2;
		k *= 2;
		j %= (x-1);
		k %= (x+1);
	}

	// cout << x << endl;

	for(i=0;i<n;i++)
	{
		if(s[i] == '0')
		{
			// ca1 (x-1)

			int te = ca2;
			te += power(2, n-1-i, (x+1));
			// cout << 'a' << power(2, n-1-i, (x+1)) << endl;
			te %= (x+1);
			cout << 1 + cnt[te] << endl;
		}
		else
		{
			if(x-1 == 0)
			{
				cout << 0 << endl;
				continue;
			}
			int te = ca1;
			te -= power(2, n-1-i, (x-1));
			te += 100*(x-1);
			te %= (x-1);
			cout << 1 + cnt[te] << endl;			
		}
	}


	return 0;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:94:35: error: no matching function for call to 'max(int, long long int)'
   94 |                         ca1 %= max(1, (x-1));
      |                                ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:94:35: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   94 |                         ca1 %= max(1, (x-1));
      |                                ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:94:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   94 |                         ca1 %= max(1, (x-1));
      |                                ~~~^~~~~~~~~~