Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define int long long

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

int main() {
  int n;
  string s;
  cin >> n >> s;

  int one_cnt = 0;
  for (int i = 0; i < n; i++) {
    if(s[i] == '1') one_cnt++;
  }

  int low = 0;
  if(one_cnt - 1 > 0) {
    for (int i = 0; i < n; i++) {
      if(s[i] == '0') continue;
      low += modpow(2, (n - 1 - i), (one_cnt - 1));
      low %= (one_cnt - 1);
    }
  }

  int high = 0;
  for (int i = 0; i < n; i++) {
    if(s[i] == '0') continue;
    high += modpow(2, (n - 1 - i), (one_cnt + 1));
    high %= (one_cnt + 1);
  }

  for (int i = 0; i < n; i++) {
    int mod = 0;
    int val = 0;
    int two = 0;

    if (s[i] == '1') {
      if (one_cnt - 1 == 0) {
        cout << 0 << '\n';
        break;
      }
      mod = (one_cnt - 1);
      val = low;
      two = modpow(2, (n - 1 - i), mod);
      val = (val - two + mod) % mod;
    } else {
      mod = (one_cnt + 1);
      val = high;
      two = modpow(2, (n - 1 - i), mod);
      val = (val + two) % mod;
    }

    int ans = 1;
    mod = __builtin_popcount(val);

    while(val != 0 && mod != 0) {
      val = val % mod;
      mod = __builtin_popcount(val);
      ans++;
    }
    cout << ans << '\n';
  }

  return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:32:20: error: no matching function for call to 'modpow(int, long long int, long long int)'
   32 |       low += modpow(2, (n - 1 - i), (one_cnt - 1));
      |              ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:7:3: note: candidate: 'template<class T> T modpow(T, T, T)'
    7 | T modpow(T base, T exp, T modulus) {
      |   ^~~~~~
a.cc:7:3: note:   template argument deduction/substitution failed:
a.cc:32:20: note:   deduced conflicting types for parameter 'T' ('int' and 'long long int')
   32 |       low += modpow(2, (n - 1 - i), (one_cnt - 1));
      |              ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:40:19: error: no matching function for call to 'modpow(int, long long int, long long int)'
   40 |     high += modpow(2, (n - 1 - i), (one_cnt + 1));
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:7:3: note: candidate: 'template<class T> T modpow(T, T, T)'
    7 | T modpow(T base, T exp, T modulus) {
      |   ^~~~~~
a.cc:7:3: note:   template argument deduction/substitution failed:
a.cc:40:19: note:   deduced conflicting types for parameter 'T' ('int' and 'long long int')
   40 |     high += modpow(2, (n - 1 - i), (one_cnt + 1));
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:56:19: error: no matching function for call to 'modpow(int, long long int, long long int&)'
   56 |       two = modpow(2, (n - 1 - i), mod);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:7:3: note: candidate: 'template<class T> T modpow(T, T, T)'
    7 | T modpow(T base, T exp, T modulus) {
      |   ^~~~~~
a.cc:7:3: note:   template argument deduction/substitution failed:
a.cc:56:19: note:   deduced conflicting types for parameter 'T' ('int' and 'long long int')
   56 |       two = modpow(2, (n - 1 - i), mod);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:61:19: error: no matching function for call to 'modpow(int, long long int, long long int&)'
   61 |       two = modpow(2, (n - 1 - i), mod);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:7:3: note: candidate: 'template<class T> T modpow(T, T, T)'
    7 | T modpow(T base, T exp, T modulus) {
      |   ^~~~~~
a.cc:7:3: note:   template argument deduction/substitution failed:
a.cc:61:19: note:   deduced conflicting types for parameter 'T' ('int' and 'long long int')
   61 |       two = modpow(2, (n - 1 - i), mod);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~