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

const int N=2e+5+5;
int f[N],n,bc,r[2][N];

int main()
{
	string x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		int g=__builtin_popcount(i);
		f[i]=1+f[i%g];
	}
	//cout<<f[1]<<" ";
	for(auto it:x)
		bc+=it-'0';
	int r1=0,r0=0;
	bc++;
	for(int i=n-1;i>=0;i--)
	{
		r[0][i]=(r[0][i+1]*2)%bc;
		r[0][n-1]=1;
	}		
	for(int i=0;i<=n-1;i++)
		r0=(r0+(x[i]-'0')*r[0][i])%bc;
	bc--;
	bc--;
	for(int i=n-1;i>=0&&bc>0;i--)
	{
		r[1][i]=(r[1][i+1]*2)%bc;
		r[1][n-1]=1;
	}
	for(int i=0;i<=n-1&&bc>0;i++)
		r1=(r1+((x[i]-'0')*r[1][i]))%bc;
	bc++;
	//cout<<r1<<" "<<r0<<" ";
	for(int i=0;i<n;i++)
	{		
		int g=0;
		if(x[i]=='1')
		{
			bc--;
			if(bc>0)
				g=((r1-r[1][i])%bc+bc)%bc;
			//cout<<bc<<" "<<r[1][i]<<" ";
			bc++;
		}
		else
		{
			bc++;
			g=(r0+r[0][i])%bc;
			//cout<<bc<<" "<<r[0][i]<<" ";
			bc--;
		}
		if(bc>1||x[i]=='0')
		{
			//cout<<bc<<" ";	
			cout<<f[g]+1<<"\n";
		}
		else 
			cout<<0<<"\n";
	}
}

