Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,int>
#define T tuple<int,int,int> 
using namespace std;

ll ni(ll a,ll b){
    if(b==0) return 1;
    else if(b%2==0) return ni(a,b/2)*ni(a,b/2);
    else return ni(a,b-1)*a;
}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    ll one=0;
    rep(i,n){
        if(s[i]=='1') one++;
    }
    if(one==0){
        rep(i,n) cout << 1 << endl;
        return 0;
    }
    vector<ll> amari0(n,0);
    vector<ll> amari1(n,0);
    amari0[n-1]=1%(one+1);
    if(one!=1) amari1[n-1]=1%(one-1);
    if(one!=1){
    rep(i,n-1){
        amari0[n-i-2]=(amari0[n-i-1]*2)%(one+1);
        if(amari0[n-i-1]==0){
            int j=0;
            while(n-i+j<n){
                if(amari0[n-i+j]!=0){
                    amari0[n-i-2]=(amari0[n-i+j]*ni(2,j+2))%(one+1);
                    break;
                }
                j++;
            }
        }
        amari1[n-i-2]=(amari1[n-i-1]*2)%(one-1);
        if(amari1[n-i-1]==0){
            int j=0;
            while(n-i+j<n){
                if(amari1[n-i+j]!=0){
                    amari1[n-i-2]=(amari1[n-i+j]*ni(2,j+2))%(one-1);
                    break;
                }
                j++;
            }
        }
    }
    }
    else{
        amari0[n-i-2]=(amari0[n-i-1]*2)%(one+1);
        if(amari0[n-i-1]==0){
            int j=0;
            while(n-i+j<n){
                if(amari0[n-i+j]!=0){
                    amari0[n-i-2]=(amari0[n-i+j]*ni(2,j+2))%(one+1);
                    break;
                }
                j++;
            }
        }
    }

    ll fund0,fund1;
    fund0=fund1=0;
    if(one==1){
        rep(i,n){
            if(s[i]=='1'){
                cout << 1 << endl;
                continue;
            }
            else{
                if(s[n-1]=='1') cout << 2 << endl;
                else cout << 1 << endl;
            }
        }
    }
    rep(i,n){
        if(s[i]=='1'){
            fund0+=amari0[i];
            fund1+=amari1[i];
        }
    }
    rep(i,n){
        ll tone=one;
        ll tmp=0;
        ll fund00=fund0;
        ll fund11=fund1;
        if(s[i]=='0'){
            fund00+=amari0[i];
            fund00%=(one+1);
            while(fund00){
                ll now=fund00;
                tone=0;
                while(now){
                    if(now%2==1) tone++;
                    now/=2; 
                }
                if(tone==0) break;
                fund00%=tone;
                tmp++;
            }
        }
        else{
            fund11-=amari1[i];
            if(fund11<0) fund11+=one-1;
            fund11%=(one-1);
            while(fund11){
                ll now=fund11;
                tone=0;
                while(now){
                    if(now%2==1) tone++;
                    now/=2; 
                }
                if(tone==0) break;
                fund11%=tone;
                tmp++;
            }
        }
        cout << tmp+1 << endl;;
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:18: error: 'i' was not declared in this scope
   61 |         amari0[n-i-2]=(amari0[n-i-1]*2)%(one+1);
      |                  ^