private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readLong() = readLn().toLong()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map(String::toInt)
private fun readLongs() = readStrings().map(String::toLong)

fun main() {
    val n = readInt()
    val s = readLn()
    val popcnt = s.sumBy { if (it == '1') 1 else 0 }
    val mds = ArrayList<Int>()
    val p2s = ArrayList<IntArray>()
    for (m in popcnt-1..popcnt+1) {
        if (m <= 0) {
            mds.add(-1)
            p2s.add(IntArray(n))
            continue
        }
        var cur = 0
        for (c in s) {
            cur *= 2
            if (c == '1')
                cur++
            cur %= m
        }
        mds.add(cur)
        val p2 = IntArray(n)
        p2[0] = 1
        for (i in 1 until n) {
            p2[i] = p2[i - 1] * 2 % m
        }
        p2s.add(p2)
    }
    fun popCount(x : Int) : Int = if (x > 0) x % 2 + popCount(x / 2) else 0
    fun brute(x: Int) : Int = if (x == 0) 0 else 1 + brute(x % popCount(x))
    for (i in 0 until n) {
        val cmd = if (s[i] == '1') popcnt - 1 else popcnt + 1
        if (cmd == 0) {
            println(0)
            continue
        }
        var cans = if (s[i] == '1') mds[0] else mds[2]
        if (s[i] == '1') {
            cans -= p2s[0][n - i - 1]
        } else {
            cans += p2s[2][n - i - 1]
        }
        cans += cmd
        cans %= cmd
        println(brute(cans) + 1)
    }
}