import java.util.*
import kotlin.math.*

typealias Num = Int

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 998244353L

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val t = str()
	val bits = t.count {it=='1'}

	val high = bits+1
	val low = bits-1
	val highd = IntArray(n) {0}
	val lowd = IntArray(n) {0}
	highd[0] = 1
	lowd[0] = 1

	var highv = (t.last()-'0').toLong()
	var lowv = (t.last()-'0').toLong()

	for(i in 1 until t.length) {
		highd[i] = highd[i-1]*2%high
		if(low>0)
			lowd[i] = lowd[i-1]*2%low

		if(t[n-i-1]=='1') {
			highv = (highv+highd[i])%high
			if(low>0)
				lowv = (lowv+lowd[i])%low
		}
	}

	for(i in t.indices.reversed()) {
		val v =
				if(t[n-i-1]=='1') {
					if(low>0)
						(lowv-lowd[i]+low)%low
					else
						-1
				} else {
					(highv+highd[i])%high
				}
		println(if(v==-1L) 0 else f(v)+1)
	}
}

fun f(i:Long):Int = when(i) {
	0L->0
	else->1+f(i%java.lang.Long.bitCount(i))
}
