Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll binpow(ll a,ll b,ll mod)
{
    if(mod<=0) return 0;
    ll res=1;
    while(b>0)
    {
        if(b%2)
        {
            res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b/=2;
    }
    return res;

}
ll getans(string s,ll p)
{
    int n=s.length();
    ll pop=p;
  //  for(auto it : s) if(it=='1') pop++;
    ll ans=0;
    
    if(pop>0)
    {

    for(int i=0;i<n;i++)
    {
        if(s[i]=='1')
        {
            ans=(ans+binpow((ll)2,(ll)(n-1-i),pop))%pop;
            
        }
    }
    }
    return ans;

}
int solve(int ans)
{
//     int n=s.length();
//     ll pop=p;
//   //  for(auto it : s) if(it=='1') pop++;
//     ll ans=0;
//     int cnt=0;
//     if(pop>0){
//     for(int i=0;i<n;i++)
//     {
//         if(s[i]=='1')
//         {
//             ans=(ans+binpow((ll)2,(ll)(n-1-i),pop))%pop;
            
//         }
//     }
//     }
//     if(pop>0)
//     cnt++;
    int cnt=0;
     cnt++;
    while(ans>0)
    {
        int z=(__builtin_popcount(ans));
        ans=ans%z;
        cnt++;
    }
    return cnt;

}
int main()
{
    int n;
    string s;
    //int val=0;
    cin>>n;
    cin>>s;
     ll p=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1') p++;
        //val+=(1<<(n-1-i))*(s[i]-'0');
    }
   // cout<<val<<endl;
   ll ans,ans1,ans2;
   ans=getans(s,p);
   ans1=getans(s,max(p-1,0));
   ans2=getans(s,p+1);
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1')
        {
           // int x=val-(1<<(n-1-i));
           
           ll val=0;
           val=((ans1+p-1)-binpow((ll)2,(ll)n-1-i,p-1))%(p-1);
        //    if(ans1>0)
        //    cout<<solve(val,1)<<endl;
        //    else
        //    {
        //        cout<<solve(val,0)<<endl;
        //    }
         cout<<solve(val)<<endl;

           
            //cout<<solve(t,p-1)<<endl;
        }
        else
        {
           // int x=val+(1<<(n-1-i));
            ll val=0;

           val=(ans2+binpow((ll)2,(ll)n-1-i,p+1))%(p+1);
        //    if(ans2>0)
        //    cout<<solve(val,1)<<endl;
        //    else
        //    {
        //        cout<<solve(val,0)<<endl;
        //    }

        cout<<solve(val)<<endl;

           
        }
        

    }


}

Compiler output:
a.cc: In function 'int main()':
a.cc:89:21: error: no matching function for call to 'max(long long int, int)'
   89 |    ans1=getans(s,max(p-1,0));
      |                  ~~~^~~~~~~
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:89:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   89 |    ans1=getans(s,max(p-1,0));
      |                  ~~~^~~~~~~
/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:89:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   89 |    ans1=getans(s,max(p-1,0));
      |                  ~~~^~~~~~~