import kotlin.math.max

fun popcount(x:Int):Int{
    var x = x
    var res = 0
    while(x>0) {
        if(x%2==1) res++
        x/=2
    }
    return res
}

fun calcF(n:Int):MutableList<Int> {
    var res = MutableList<Int>(n+1,{_->0})
    for(i in 1..n){
        res[i] = res[i%popcount(i)]+1;
    }
    return res
}

fun calcSum(x:List<Int>,p:Int):Int{
    var base = 1
    var sum = 0
    for(i in x.indices.reversed()){
        sum+=x[i]*base
        sum%=p
        base=base*2%p
    }
    return sum
}
fun main() {
    val n = readLine()!!.toInt()
    val x = readLine()!!.map({c -> c-'0'})
    
    val cntx = x.sum()
    val f = calcF(n)

    val pFor1 = max(cntx-1,1)
    val pFor0 = cntx+1
    val sumFor1 = calcSum(x,pFor1)
    val sumFor0 = calcSum(x,pFor0)

    var base0 = 1
    var base1 = 1
    var res = MutableList<Int>(n,{_->0})
    for(i in n-1 downTo 0){
        if(cntx==1 && x[i]==1){
            res[i] = 0
        }
        else{
            var tar:Int
            if(x[i]==0){
                tar = sumFor0+base0
                tar = (tar%pFor0+pFor0)%pFor0
            }
            else{
                tar = sumFor1-base1
                tar = (tar%pFor1+pFor1)%pFor1
            }
            res[i] = f[tar]+1
        }
        base0=base0*2%pFor0
        base1=base1*2%pFor1
    }
    for(i in 0 until n){
        println(res[i])
    }
}
