fun popCount(bits: Long): Long {
    var b = bits
    b -= ((b shr 1) and 0x5555555555555555)
    b = (b and 0x3333333333333333) + ((b shr 2) and 0x3333333333333333)
    b = (b + (b shr 4)) and 0x0f0f0f0f0f0f0f0f
    b += (b shr 8)
    b += (b shr 16)
    b += (b shr 32)
    return b and 0x0000007f
}

fun modPow(_a: Long, _n: Long, mod: Long): Long {
    var res = 1L
    var a = _a
    var n = _n
    while (n > 0) {
        if (n and 1 == 1L) res = res * a % mod
        a = a * a % mod
        n = n shr 1
    }
    return res
}

fun f(_n: Long): Int {
    var n = _n
    var res = 0
    while (n > 0) {
        n %= popCount(n)
        res += 1
    }
    return res
}

fun main() {
    val n = readLine()!!.toInt()
    val x = readLine()!!

    val popCountX = x.count { it == '1' }
    val a0 = popCountX - 1
    val a1 = popCountX + 1
    var a0mod = 0L
    var a1mod = 0L

    for (b in x) {
        if (a0 != 0) {
            a0mod = (a0mod * 2 + b.toInt() - '0'.toInt()) % a0
        }
        a1mod = (a1mod * 2 + b.toInt() - '0'.toInt()) % a1
    }

    for (i in (0 until n).reversed()) {
        val res = if (x[n - 1 - i] == '1') {
            if (a0 != 0) {
                var next = a0mod
                next -= modPow(2L, i.toLong(), a0.toLong())
                while (next < 0) next += a0
                f(next) + 1
            } else {
                0
            }
        } else {
            var next = a1mod
            next += modPow(2L, i.toLong(), a1.toLong())
            next %= a1
            f(next) + 1
        }
        println(res)
    }
}