unittest
{
	assert( [ "3", "011" ].solve == "2\n1\n1" );
	assert( [ "23", "00110111001011011001110" ].solve == "2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3" );
	
	assert( [ "3", "000" ].solve == "1\n1\n1" );		// 追加ケース
	assert( [ "3", "100" ].solve == "0\n1\n2" );		// 追加ケース
	assert( [ "3", "111" ].solve == "2\n2\n1" );		// 追加ケース
}



import core.bitop;
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto x = input.front.to!( dchar[] );
	
	auto px = x.count( '1' );
	auto pm = px - 1;
	auto pp = px + 1;
	auto rm = 0L;
	auto rp = 0L;
	foreach( i, b; x )
	{
		if( b != '1' ) continue;
		if( 0 < pm ) rm = ( rm + remainder( 1, n - 1 - i, pm ) ) % pm;
		rp = ( rp + remainder( 1, n - 1 - i, pp ) ) % pp;
	}
	
	auto anss = new long[ n ];
	foreach( i, ref ans, b; lockstep( anss, x ) )
	{
		auto p = ( b == '1' ) ? pm : pp;
		if( p <= 0 ) continue;
		auto r = ( b == '1' ) ? rm : rp;
		if( b == '1' ) r = ( r - remainder( 1, n - 1 - i, p ) + p ) % p;
		else           r = ( r + remainder( 1, n - 1 - i, p ) ) % p;
		ans++;
		for( ; 0 < r; p = r._popcnt, r %= p )
		{
			ans++;
		}
	}
	return anss.to!( string[] ).join( "\n" );
}

// ( n << x ) % m を計算
auto remainder( long n, long x, long m )
{
	static long[][] memo;
	if( memo.length <= m ) memo.length = m + 1;
	if( memo[ m ].empty ) memo[ m ] = [ 1L ];
	if( memo[ m ].length <= x )
	{
		auto i = memo[ m ].length.signed;
		memo[ m ].length = x + 1;
		for( ; i <= x; i++ )
		{
			memo[ m ][ i ] = ( memo[ m ][ i - 1 ] << 1 ) % m;
		}
	}
	return ( memo[ m ][ x ] * n ) % m;
}
