#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi pre(N);
int compute(int n)
{   int cnt=0;
    while(n>0)
    {int p=__builtin_popcount(n);
     n%=p;
     cnt++;
    }
    return cnt;

}
int power(int x, int y, int p)
{
    int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0 && y!=0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   for(int i=1;i<N;i++)
    pre[i]=compute(i);
   int n;
   cin>>n;
   string s;
   cin>>s;
   int val=0;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]=='1')val++;
   }
   reverse(all(s));
   int num1=0,num2=0;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]=='1')
       {
           num1+=power(2,i,val+1);
           if(val>1)
           num2+=power(2,i,val-1);
           num1%=(val+1);
           if(val>1)
           num2%=(val-1);
       }
   }
   vi ans;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]=='1')
       {
           int rem=0;
           if(val == 1)
           {
               ans.pb(rem);
               continue;
           }
           int temp=num2;
           temp=(temp - power(2,i,(val-1)) + (val - 1))%(val - 1);
           rem=1+pre[temp];
           ans.pb(rem);
       }
       else
       {
           int rem=0;
           int temp=num1;
           temp=(temp + power(2,i,val+1))%(val+1);
           rem=1+pre[temp];
           ans.pb(rem);
       }
   }
   reverse(all(ans));
   for(auto x:ans)
    cout<<x<<endl;

}


Measured memory_bytes: 7052