#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;            typedef vector<vi> vii;
typedef vector<ll> vl;             typedef vector<vl> vll;
typedef pair<int,int> pi;          typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;            typedef pair<pl,ll> pll;
typedef pair<int,bool> pib;        typedef pair<ll,bool> plb;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define in insert
#define er erase
//user-defined hash table for pairs --------------------------------------------------------------------------------------------------
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

//returns (a^n mod p)---------------------------------------------------------------------------------------------------------------
ll power(ll a,ll n,ll p)
{
	if(n == 0)
	{
		return 1;
	}
	else if(n%2 == 0)
	{
		ll ans = power(a,n/2,p);
		return (ans*ans)%p;
	}
	else 
	{
		ll ans = power(a,n-1,p);
		return (ans*a)%p;
	}
}

//returns (a^-1 mod p)(if p is prime)----------------------------------------------------------------------------------------------
ll inverse(ll a,ll p)
{
   return power(a,p-2,p);
}
//----------------------------------------------------------------------------------------------------------------------------------


void solve()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   int cnt = 0;
   for(int i=0;i<n;i++)
   {
   	  if(s[i] == '1')
   	  {
   	  	cnt++;
   	  }
   }
   if(cnt == 0)
   {
   	  for(int i=0;i<n;i++)
   	  {
   	  	cout<<1<<endl;
   	  }
   }
   else if(cnt == 1)
   {
   	  for(int i=0;i<n;i++)
   	  {
   	  	 if(s[i] == '1')
   	  	 {
   	  	 	cout<<0<<endl;
   	  	 }
   	  	 else
   	  	 {
   	  	 	if(s[n-1] == '1' || i == n-1)
   	  	 	{
   	  	 		cout<<2<<endl;
   	  	 	}
   	  	 	else
   	  	 	{
   	  	 		cout<<1<<endl;
   	  	 	}
   	  	 }
   	  }
   }
   else
   {
   	   int rem1[n],rem2[n];
   	   ll pwr = 1;
   	   ll sum1 = 0,sum2 = 0;
   	   for(int i=n-1;i>=0;i--)
   	   {
          rem1[i] = pwr%(cnt-1);
          pwr = (pwr*2)%(cnt-1);
          if(s[i] == '1')
          {
            sum1 = (sum1+rem1[i])%(cnt-1);
          }
   	   }
   	   pwr = 1;
   	   for(int i=n-1;i>=0;i--)
   	   {
   	   	  rem2[i] = pwr%(cnt+1);
   	   	  pwr = (pwr*2)%(cnt+1);
   	   	  if(s[i] == '1')
   	   	  {
   	   	  	 sum2 = (sum2+rem2[i])%(cnt+1);
   	   	  }
   	   }
   	   for(int i=0;i<n;i++)
   	   {
   	   	  if(s[i] == '1')
   	   	  {
   	   	  	 int temp = (sum1-rem1[i]+cnt-1)%(cnt-1);
   	   	  	 int curr = 1;
   	   	  	 while(temp > 0)
   	   	  	 {
   	   	  	 	int temp1 = temp;
   	   	  	 	int pcnt = 0;
   	   	  	    while(temp1 > 0)
   	   	  	    {
                   if(temp1%2 == 1)
                   {
                   	  pcnt++;
                   }
                   temp1 = temp1/2;
   	   	  	    }
   	   	  	    temp = temp%pcnt;
   	   	  	    curr++;
   	   	  	 }
   	   	  	 cout<<curr<<endl;
   	   	  }
   	   	  else
   	   	  {
   	   	  	int temp = (sum2+rem2[i])%(cnt+1);
   	   	  	int curr = 1;
   	   	  	while(temp > 0)
   	   	  	{
   	   	  		int temp1 = temp;
   	   	  		int pcnt = 0;
   	   	  		while(temp1 > 0)
   	   	  		{
   	   	  			if(temp1%2 == 1)
   	   	  			{
   	   	  				pcnt++;
   	   	  			}
   	   	  			temp1 = temp1/2;
   	   	  		}
   	   	  		temp = temp%pcnt;
   	   	  		curr++;
   	   	  	}
   	   	  	cout<<curr<<endl;
   	   	  }
   	   }
   }
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef PAVANSAI006
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    ll t = 1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
    
}

Measured memory_bytes: 5260