Language: C++

#pragma GCC optimze("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// inbuilt function in c++
// abs(-2)=2 , __gcd(2,3)=1 , swap(a,b) , 
//string/array s = "aba"; sort(s.begin(), s.end());  do {  cout << s << '\n';  } while(next_permutation(s.begin(), s.end()));  
//for all permutation of s.
// priority_queue stores the values in descending order q.front() returns maximum element. ".size() works for priority_queue."
#include <bits/stdc++.h>
#define int                 long long int
#define double              long double
#define get(a,n)            for(int i=0;i<n;i++){cin>>a[i];}
#define maxm(a)             int maxi=LLONG_MIN;int index;for(int i=0;i<n;i++){if(maxi<a[i]){maxi=a[i];index=i;}}
#define minm(a)             int mini=LLONG_MAX;int index;for(int i=0;i<n;i++){if(mini>a[i]){mini=a[i];index=i;}}
#define db(x)               cout<<"["<<x<<"]"<<endl;
#define endl                "\n"
#define PI                  acos(-1)
#define half(a)             a%2?(a/2+1):a/2
#define array               int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define pb                push_back
#define all(a)              a.begin(),a.end()
#define mod                 1000000007
using namespace std;
int  por(int x,int y, int p) 
{ 
    int res = 1;
    x = x % p;
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p; 
    } 
    return res; 
}
int modInverse(int n, int p) {return por(n, p - 2, p);} 
int nCrModPFermat(int  n, int r, int p) 
{ 
    if (r == 0) return 1; 
    int  fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}
template <typename T>
void printvec(vector<T>& vec){
	for(int i=0;i<vec.size();i++) cout<<vec[i]<<" ";
	cout<<endl;
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second<b.second);
}
vector<int> p;
int fprime=0;
void seiveprime(int n) 
{ 
    fprime=123;
    bool pr[n+1]; 
    memset(pr, true, sizeof(pr)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (pr[p] == true) 
        {
            for (int i=p*p; i<=n; i += p) 
                pr[i] = false; 
        } 
    } 
    for (int p0=2; p0<=n; p0++) 
       if (pr[p0]) 
          p.pb(p0); 
} 
void show(int *a)
{
    int size = (*(&a + 1) - a)-1;
    for(int i=0;i<size;i++)
    {
            cout<<a[i]<<" ";
    }   
    cout<<endl;
}
int binary_search(int *a,int n,int e)
{
    int f,l,m;f=0;l=n-1;
    while(f<=l)
    {//returns index of that value.
        m=(f+l)/2;
        if(e==a[m])
            return(m);
        else if(e>a[m])
                f=m+1;
            else
                l=m-1;
    }
    return -1;
}
vector<int> pf;
void primefactors(int n)  
{  
    while (n % 2 == 0)  
    pf.push_back(2),n = n/2;  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            pf.push_back(i); 
            n = n/i;  
        }  
    }  
    if (n > 2)  
        pf.push_back(n);
        //dont forgot to clear pf vector. 
}  
//vector<int,greater<int>>fac;
vector<int> fac;
void factors(int n) 
{ 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            if (n/i == i) 
            fac.push_back(i);
            else
            fac.push_back(i),fac.push_back(n/i); 
        } 
    } 
    //dont forgot to clear fac vector.
} 
int power(int x, int y, unsigned int p=ULLONG_MAX)  
{  
    int res = 1;     
    x = x % p; 
    if (x == 0) 
      return 0; 
    while (y > 0)  
    {    
        if (y & 1)  
           res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
void solve()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   bitset<n+1> b(s);
   int f[n+1];f[0]=0;
   for(int i=1;i<=n;i++)
   {
       bitset<32> w(i);
       f[i]=f[i%(w.count())]+1;
      // cout<<f[i]<<" ";
   }
   int z=b.count();
  int sum=0,sum1=0;int md=z-1,md1=z+1;
   for(int i=0;i<n;i++)
   {
      // int md=z-1;
      if(b[i]==1){
        sum=(sum%md+power(2,i,md)%md)%md;
       // int md1=z+1;
        sum1=(sum1%md1+power(2,i,md1)%md1)%md1;
      }
   }
   for(int i=n-1;i>=0;i--)
   {
       if(b[i]==0)
       {
           int k=(sum1+power(2,i,md1))%md1;
           cout<<f[k]+1<<endl;
       }
       else
       {
           int k=(sum-power(2,i,md)+md)%md;
           cout<<f[k]+1<<endl;
       }
   }
   
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(15);
    int t=1;
  //  cin>>t;
    //seiveprime(1000);
    while(t--)
    {
        solve();
        
    }
   

  
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:152:13: error: the value of 'n' is not usable in a constant expression
  152 |    bitset<n+1> b(s);
      |             ^
a.cc:148:8: note: 'long long int n' is not const
  148 |    int n;
      |        ^
a.cc:152:14: error: the value of 'n' is not usable in a constant expression
  152 |    bitset<n+1> b(s);
      |              ^
a.cc:148:8: note: 'long long int n' is not const
  148 |    int n;
      |        ^
a.cc:152:12: note: in template argument for type 'long unsigned int'
  152 |    bitset<n+1> b(s);
      |           ~^~
a.cc:152:18: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'int' in initialization
  152 |    bitset<n+1> b(s);
      |                  ^
      |                  |
      |                  std::string {aka std::__cxx11::basic_string<char>}
a.cc:160:12: error: request for member 'count' in 'b', which is of non-class type 'int'
  160 |    int z=b.count();
      |            ^~~~~
a.cc:165:11: error: invalid types 'int[long long int]' for array subscript
  165 |       if(b[i]==1){
      |           ^
a.cc:173:12: error: invalid types 'int[long long int]' for array subscript
  173 |        if(b[i]==0)
      |            ^