Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
 
int main(){
 
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
 
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ones = 0;
 
  for(long long i=0;i<n;i++){
    if(s[i] == '1')
      ones++;
  }
 
  if(ones == 0){
    for(long long i=0;i<n;i++)
      cout << 0 << endl;
    return 0;
  }

  long long plus = ones+1;
  long long minus = ones-1;
  minus = max(1,minus);

  vector <long long> powerTwo[2];
  powerTwo[0].resize(n);
  powerTwo[1].resize(n);
 
  powerTwo[0][0] = 1%minus;
  for(long long i=1;i<n;i++){
    powerTwo[0][i] = powerTwo[0][i-1]*(2%minus);
    powerTwo[0][i] %= minus;
  }
 
  powerTwo[1][0] = 1%plus;
  for(long long i=1;i<n;i++){
    powerTwo[1][i] = powerTwo[1][i-1]*(2%plus);
    powerTwo[1][i] %= plus;
  }
 
  
  vector <long long> sufPlus(n+1);
  sufPlus[n] = 0;
  vector <long long> sufMinus(n+1);
  sufMinus[n] = 0;
 
  for(long long i=n-1;i>=0;i--){
    if(s[i] == '1'){
      sufMinus[i] = sufMinus[i+1] + powerTwo[0][n-i-1];
      sufMinus[i] %= minus;
    }else{
      sufMinus[i] = sufMinus[i+1];
      sufMinus[i] %= minus;
    }
  }
 
  for(long long i=n-1;i>=0;i--){
    if(s[i] == '1'){
      sufPlus[i] = sufPlus[i+1] + powerTwo[1][n-i-1];
      sufPlus[i] %= plus;
    }else{
      sufPlus[i] = sufPlus[i+1];
      sufPlus[i] %= plus;
    }
  }
 
  for(long long i=0;i<n;i++){
    if(ones == 1 && s[i] == '1'){
      cout << 0 << endl;
      continue;
    }
    long long cur;
    if(s[i] == '1'){
      cur = sufMinus[i+1] + (sufMinus[0]-sufMinus[i]);
      cur %= minus;
      if(cur < 0)
        cur += minus;
    }else{
      cur = sufPlus[0] + powerTwo[1][n-i-1];
      cur %= plus;
    }
 
    long long op = 1;
      while(cur){
        long long bin = __builtin_popcount(cur);
        cur = cur%bin;
        op++;
      }
      cout << op << endl;
  }
 
  return 0;
}

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