func main() {
let n = Int(readLine()!)!
let x = readLine()!
var xn = 0

for i in 0..<n {
    let ind = x[x.index(x.startIndex, offsetBy: i)]
    if ind == "1" {
        xn += pow(2, n-1-i)
    }
}

for i in 0..<n {
    let s = x[x.index(x.startIndex, offsetBy: i)]
    let m = s == "1" ? 1: -1
    let xy = xn - pow(2, n-1-i) * m
    print(f(xy))
}

}
main()
func pow(_ n: Int, _ m: Int) -> Int{
    var a = 1
    if m >= 1 {
        for _ in 1...m {
            a *= n
        }
    }
    return a
}

func pc(_ n: Int) -> Int {
    let b = String(n, radix: 2)
    var c = 0
    for d in b {
        if d == "1" {
            c += 1
        }
    }
    return c
}

func f(_ n: Int) -> Int {
    var c = 0
    var n = n
    while n != 0 {
        n = n % pc(n)
        c += 1
    }
    return c
}
