Language: C++

#include <bits/stdc++.h>

//Common
using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;template<typename T> using Func=function<T>;template<typename T> using Str=basic_string<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQMIN(...) std::priority_queue<__VA_ARGS__,Arr<__VA_ARGS__>,greater<__VA_ARGS__>>
template<class... A>
auto ARR(auto n, A&&...a){
	if constexpr(sizeof...(a)==0) return n;
	else return vector(n,ARR(a...));
}

//Math
template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
template<typename T> inline T sq(T x){return x*x;}
cxp int lgc(int x){return 64-__builtin_clzll(x-1);}
cxp int lgf(int x){return 63-__builtin_clzll(x);}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1), eps=1e-10;

//IO
template<typename T>ostream& operator<<(ostream& s, const Arr<T>& a) {for(auto i:a) cout<<i<<' '; return s;}
auto cinint(){i64 x;cin>>x;return x;}
auto cinchr(){char x;cin>>x;return x;}
auto cinints(int n){Arr<i64> a(n);for(auto&i:a)cin>>i;return a;}
#ifndef DEBUG
	//#pragma GCC optimize ("Ofast") //somtimes it become more slower
	auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif

//Misc
int sz(const auto& x){return x.size();}
auto split(auto s, auto p){
	Arr<decltype(s)> ret;
	auto it1=s.begin();
	for(auto it2=it1; (it2 = find(it1,s.end(),p)) != s.end(); it1=it2+1)
		ret.pushb({it1, it2});
	ret.pushb({it1,s.end()});
	return ret;
}
template<typename T> T rev(const T& a){return {a.rbegin(),a.rend()};}
Arr<int> range(int n){ Arr<int> ret(n); rep(i,n)ret[i]=i; return ret; }
struct defer{ defer(auto f):f(f){} ~defer(){f();} function<void()> f; };
#define defer(x) auto _##__COUNTER__ = defer([&](){x;});
#define lam(expr, ...) [&](__VA_ARGS__){return expr;}
#define reduce accumulate

#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

int f(Arr<int> x){
	int c=0;
	for(auto i:x)
		c+=i;
	int r=0;
	int p=1;
	rep(i,sz(x)){
		if(x[i])
			r=(r+p)%c;
		p=p*2%c;
	}
	return r;
}

Arr<int> ff(int x){
	Arr<int> z;
	while(x){
		z.pushb(x%2);
		x/=2;
	}
	return z;
}

int g(int x){
	int r=0;
	while(x)
		x=f(ff(x)),r++;
	return r;
}

int fp(int a, int p, int m){
	if(!p)
		return 1;
	int z=fp(a,p/2);
	return z*z*(p%2?a:1)%m;
}

signed main(){
	int n; cin>>n;
	string x; cin>>x;
	reverse(all(x));
	Arr<int> z;
	for(auto i:x)
		z.pushb(i-'0');
	int zz=f(z);
	Arr<int> ans;
	int c=0;
	for(auto i:z)
		c+=i;

	rep(i,n){

		cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
	}

	return 0;
}



Compiler output:
a.cc:30:10: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   30 | auto ARR(auto n, A&&...a){
      |          ^~~~
a.cc:55:14: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   55 | int sz(const auto& x){return x.size();}
      |              ^~~~
a.cc:56:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   56 | auto split(auto s, auto p){
      |            ^~~~
a.cc:56:20: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   56 | auto split(auto s, auto p){
      |                    ^~~~
a.cc:66:21: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   66 | struct defer{ defer(auto f):f(f){} ~defer(){f();} function<void()> f; };
      |                     ^~~~
a.cc: In function 'i64 fp(i64, i64, i64)':
a.cc:109:17: error: too few arguments to function 'i64 fp(i64, i64, i64)'
  109 |         int z=fp(a,p/2);
      |               ~~^~~~~~~
a.cc:106:5: note: declared here
  106 | int fp(int a, int p, int m){
      |     ^~
a.cc: In function 'int main()':
a.cc:128:26: error: no match for 'operator+' (operand types are 'Arr<long long int>' {aka 'std::vector<long long int, std::allocator<long long int> >'} and 'i64' {aka 'long long int'})
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                         ~^~~~~~~~~~~~~~~~~~~~~~
      |                         |   |
      |                         |   i64 {aka long long int}
      |                         Arr<long long int> {aka std::vector<long long int, std::allocator<long long int> >}
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 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_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'i64' {aka 'long long int'}
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'i64' {aka 'long long int'}
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   'Arr<long long int>' {aka 'std::vector<long long int, std::allocator<long long int> >'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   mismatched types 'const _CharT*' and 'std::vector<long long int, std::allocator<long long int> >'
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'i64' {aka 'long long int'}
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   'Arr<long long int>' {aka 'std::vector<long long int, std::allocator<long long int> >'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   'Arr<long long int>' {aka 'std::vector<long long int, std::allocator<long long int> >'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   'Arr<long long int>' {aka 'std::vector<long long int, std::allocator<long long int> >'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   'Arr<long long int>' {aka 'std::vector<long long int, std::allocator<long long int> >'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   'Arr<long long int>' {aka 'std::vector<long long int, std::allocator<long long int> >'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  128 |                 cout<<g(z+fp(2,i,c+(z[i]?-1:1)))<<endl;
      |                                               ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc:128:47: note:   mismatched types 'const _CharT*' and 'std::vector<long long int, std::allocator<long long int> >'