import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun next(X: IntArray, popCount: Int): Int {
        var ans = 0
        var d = 1
        for (i in X.count() - 1 downTo 0) {
            if (X[i] == 1) {
                ans += d % popCount
                ans %= popCount
            }
            d *= 2
            d %= popCount
        }
        return ans
    }

    private fun popCount(X: Int): Int {
        var i = X
        var ans = 0
        do {
            ans += i and 1
            i /= 2
        } while (i > 0)
        return ans
    }

    fun next(X: Int): Int {
        var ans = 0
        var d = 1
        val div = popCount(X)
        var x = X
        while (x > 0) {
            if (x and 1 == 1) {
                ans += d % div
                ans %= div
            }
            d *= 2
            d %= div
            x /= 2
        }
        return ans
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val X = sc.next().map { it.toInt() - 48 }.toIntArray()

        val nxt = IntArray(N)
        for (i in 1 until N) {
            nxt[i] = next(i)
        }

        val nxt2 = IntArray(N)
        val popCount = X.count { it == 1 }
        val popCountMinus = popCount - 1
        val popCountPlus = popCount + 1
        val nxtMinus = if (popCountMinus == 0) -1 else next(X, popCountMinus)
        val nxtPlus = next(X, popCountPlus)
        var dMinus = 1
        var dPlus = 1
        for (i in N - 1 downTo 0) {
            if (X[i] == 1) {
                // 1 -> 0
                if (popCountMinus == 0) {
                    nxt2[i] = -1
                } else {
                    nxt2[i] = nxtMinus - dMinus
                    nxt2[i] += popCountMinus
                    nxt2[i] %= popCountMinus
                }
            } else {
                // 0 -> 1
                nxt2[i] = nxtPlus + dPlus
                nxt2[i] %= popCountPlus
            }
            if (popCountMinus != 0) {
                dMinus *= 2
                dMinus %= popCountMinus
            }
            dPlus *= 2
            dPlus %= popCountPlus
        }

        for (i in 0 until N) {
            var x = nxt2[i]
            if (x == -1) {
                pw.println("0")
            } else {
                var ans = 1
                while (x > 0) {
                    x = nxt[x]
                    ans++
                }
                pw.println(ans)
            }
        }
    }
}
