Language: C++

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

int  mod = 1000000007;

struct mint{
    ll x;
    mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod) x-=mod;
        return *this;//thisとは現在のオブジェクトのこと
    }
    mint& operator-=(const mint a){
        if((x +=mod-a.x)>=mod) x-=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod-2);//逆元
    }
    mint&operator/=(const mint a) {
        return (*this)*=a.inv();
    }
    mint&operator/(const mint a) const{
    mint res(*this);
    return res/=a;
    }
};

struct mint2{
    ll x;
    mint (ll x=0) : x((x%mod2+mod2)%mod2){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod2) x-=mod2;
        return *this;//thisとは現在のオブジェクトのこと
    }
    mint& operator-=(const mint a){
        if((x +=mod2-a.x)>=mod2) x-=mod2;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod2;
        return *this;
    }
    mint operator+(const mint a){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod2-2);//逆元
    }
    mint&operator/=(const mint a) {
        return (*this)*=a.inv();
    }
    mint&operator/(const mint a) const{
    mint res(*this);
    return res/=a;
    }
};

int g(int n){
    int count = __builtin_popcount(n);
    return n%count;
}

int main(void){
    int n;
    cin>>n;
    string x;
    cin>>x;
    int pop_count = 0;
    rep(i, x.size()){
        if(x[i] == '1') pop_count++;
    }
    const int mod = pop_count+1;
    const int mo2 = pop_count-1;
    if(pop_count == 1){
        rep(i, n){
            if(x[i] == '1') cout<<0<<endl;
            else cout<<1<<endl;
        }
    }
    else if(pop_count == 0){
        rep(i, n) {
            cout<<1<<endl;
        }
    }
    else{
        mint now2 = 0;
        mint t = 1;
        vector<mint>beki2(n);
        rep(i, n){
            beki2[i]=t;
            mint a = x[n-1-i]-'0';
            now2 += t * a;
            t *= 2;
        }

        mint2 now3 = 0;
        mint2 t = 1;
        vector<mint2>beki3(n);
        rep(i, n){
            beki3[i]=t;
            mint2 a = x[n-1-i]-'0';
            now3 += t * a;
            t *= 2;
        }
        rep(i, n){
            int k = n-1-i;
            if(x[i] == '1'){
                mint2 p = now3 - beki3[k];
                int u = p.x;
                //cout<<u<<endl;
                int ans = 1;
                while(u>0){
                    u = g(u);
                    ans++;
                }
                cout<<ans<<endl;
            }
            else{
                mint p = now2 + beki2[k];
                int u = p.x;
                //cout<<u<<endl;
                int ans = 1;
                while(u>0){
                    u = g(u);
                    ans++;
                }
                cout<<ans<<endl;
            }
        }
    }
    return 0;
}

Compiler output:
a.cc:56:13: error: expected ')' before 'x'
   56 |     mint (ll x=0) : x((x%mod2+mod2)%mod2){}//カッコの中で初期化している
      |          ~  ^~
      |             )
a.cc: In member function 'mint& mint2::operator+=(mint)':
a.cc:58:23: error: 'mod2' was not declared in this scope; did you mean 'modf'?
   58 |         if((x +=a.x)>=mod2) x-=mod2;
      |                       ^~~~
      |                       modf
a.cc:59:16: error: invalid initialization of reference of type 'mint&' from expression of type 'mint2'
   59 |         return *this;//thisとは現在のオブジェクトのこと
      |                ^~~~~
a.cc: In member function 'mint& mint2::operator-=(mint)':
a.cc:62:17: error: 'mod2' was not declared in this scope; did you mean 'modf'?
   62 |         if((x +=mod2-a.x)>=mod2) x-=mod2;
      |                 ^~~~
      |                 modf
a.cc:63:16: error: invalid initialization of reference of type 'mint&' from expression of type 'mint2'
   63 |         return *this;
      |                ^~~~~
a.cc: In member function 'mint& mint2::operator*=(mint)':
a.cc:66:19: error: 'mod2' was not declared in this scope; did you mean 'modf'?
   66 |         (x*=a.x)%=mod2;
      |                   ^~~~
      |                   modf
a.cc:67:16: error: invalid initialization of reference of type 'mint&' from expression of type 'mint2'
   67 |         return *this;
      |                ^~~~~
a.cc: In member function 'mint mint2::operator+(mint)':
a.cc:70:23: error: no matching function for call to 'mint::mint(mint2&)'
   70 |         mint res(*this);
      |                       ^
a.cc:10:5: note: candidate: 'mint::mint(ll)'
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |     ^~~~
a.cc:10:14: note:   no known conversion for argument 1 from 'mint2' to 'll' {aka 'long long int'}
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |           ~~~^~~
a.cc:8:8: note: candidate: 'constexpr mint::mint(const mint&)'
    8 | struct mint{
      |        ^~~~
a.cc:8:8: note:   no known conversion for argument 1 from 'mint2' to 'const mint&'
a.cc:8:8: note: candidate: 'constexpr mint::mint(mint&&)'
a.cc:8:8: note:   no known conversion for argument 1 from 'mint2' to 'mint&&'
a.cc: In member function 'mint mint2::operator-(mint)':
a.cc:74:23: error: no matching function for call to 'mint::mint(mint2&)'
   74 |         mint res(*this);
      |                       ^
a.cc:10:5: note: candidate: 'mint::mint(ll)'
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |     ^~~~
a.cc:10:14: note:   no known conversion for argument 1 from 'mint2' to 'll' {aka 'long long int'}
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |           ~~~^~~
a.cc:8:8: note: candidate: 'constexpr mint::mint(const mint&)'
    8 | struct mint{
      |        ^~~~
a.cc:8:8: note:   no known conversion for argument 1 from 'mint2' to 'const mint&'
a.cc:8:8: note: candidate: 'constexpr mint::mint(mint&&)'
a.cc:8:8: note:   no known conversion for argument 1 from 'mint2' to 'mint&&'
a.cc: In member function 'mint mint2::operator*(mint)':
a.cc:78:23: error: no matching function for call to 'mint::mint(mint2&)'
   78 |         mint res(*this);
      |                       ^
a.cc:10:5: note: candidate: 'mint::mint(ll)'
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |     ^~~~
a.cc:10:14: note:   no known conversion for argument 1 from 'mint2' to 'll' {aka 'long long int'}
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |           ~~~^~~
a.cc:8:8: note: candidate: 'constexpr mint::mint(const mint&)'
    8 | struct mint{
      |        ^~~~
a.cc:8:8: note:   no known conversion for argument 1 from 'mint2' to 'const mint&'
a.cc:8:8: note: candidate: 'constexpr mint::mint(mint&&)'
a.cc:8:8: note:   no known conversion for argument 1 from 'mint2' to 'mint&&'
a.cc: In member function 'mint mint2::pow(ll) const':
a.cc:85:18: error: no match for 'operator*=' (operand types are 'mint' and 'const mint2')
   85 |         if(t&1) a*=*this;
      |                 ~^~~~~~~
a.cc:19:11: note: candidate: 'mint& mint::operator*=(mint)'
   19 |     mint& operator*=(const mint a){
      |           ^~~~~~~~
a.cc:19:33: note:   no known conversion for argument 1 from 'const mint2' to 'mint'
   19 |     mint& operator*=(const mint a){
      |                      ~~~~~~~~~~~^
a.cc: In member function 'mint mint2::inv() const':
a.cc:89:20: error: 'mod2' was not declared in this scope; did you mean 'modf'?
   89 |         return pow(mod2-2);//逆元
      |                    ^~~~
      |                    modf
a.cc: In member function 'mint& mint2::operator/(mint) const':
a.cc:95:19: error: no matching function for call to 'mint::mint(const mint2&)'
   95 |     mint res(*this);
      |                   ^
a.cc:10:5: note: candidate: 'mint::mint(ll)'
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |     ^~~~
a.cc:10:14: note:   no known conversion for argument 1 from 'const mint2' to 'll' {aka 'long long int'}
   10 |     mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
      |           ~~~^~~
a.cc:8:8: note: candidate: 'constexpr mint::mint(const mint&)'
    8 | struct mint{
      |        ^~~~
a.cc:8:8: note:   no known conversion for argument 1 from 'const mint2' to 'const mint&'
a.cc:8:8: note: candidate: 'constexpr mint::mint(mint&&)'
a.cc:8:8: note:   no known conversion for argument 1 from 'const mint2' to 'mint&&'
a.cc: In function 'int main()':
a.cc:138:22: error: conversion from 'int' to non-scalar type 'mint2' requested
  138 |         mint2 now3 = 0;
      |                      ^
a.cc:139:15: error: conflicting declaration 'mint2 t'
  139 |         mint2 t = 1;
      |               ^
a.cc:129:14: note: previous declaration as 'mint t'
  129 |         mint t = 1;
      |              ^
a.cc:142:22: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<mint2>, mint2>::value_type' {aka 'mint2'} and 'mint')
  142 |             beki3[i]=t;
      |                      ^
a.cc:54:8: note: candidate: 'constexpr mint2& mint2::operator=(const mint2&)'
   54 | struct mint2{
      |        ^~~~~
a.cc:54:8: note:   no known conversion for argument 1 from 'mint' to 'const mint2&'
a.cc:54:8: note: candidate: 'constexpr mint2& mint2::operator=(mint2&&)'
a.cc:54:8: note:   no known conversion for argument 1 from 'mint' to 'mint2&&'
a.cc:143:31: error: conversion from 'int' to non-scalar type 'mint2' requested
  143 |             mint2 a = x[n-1-i]-'0';
a.cc:144:23: error: no match for 'operator*' (operand types are 'mint' and 'mint2')
  144 |             now3 += t * a;
      |                     ~ ^ ~
      |                     |   |
      |                     |   mint2
      |                     mint
a.cc:31:10: note: candidate: 'mint mint::operator*(mint)'
   31 |     mint operator*(const mint a){
      |          ^~~~~~~~
a.cc:31:31: note:   no known conversion for argument 1 from 'mint2' to 'mint'
   31 |     mint operator*(const mint a){
      |                    ~~~~~~~~~~~^
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)'
  400 |     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:400:5: note:   template argument deduction/substitution failed:
a.cc:144:25: note:   'mint' is not derived from 'const std::complex<_Tp>'
  144 |             now3 += t * a;
      |                         ^
/usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)'
  409 |     operator*(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:409:5: note:   template argument deduction/substitution failed:
a.cc:144:25: note:   'mint' is not derived from 'const std::complex<_Tp>'
  144 |             now3 += t * a;
      |                         ^
/usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const complex<_Tp>&)'
  418 |     operator*(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:418:5: note:   template argument deduction/substitution failed:
a.cc:144:25: note:   'mint2' is not derived from 'const std::complex<_Tp>'
  144 |             now3 += t * a;
      |                         ^
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:144:25: note:   'mint' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  144 |             now3 += t * a;
      |                         ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  407 |