let n = Int(readLine()!)!
let xst = readLine()!
let x: Int = {
    var c = 0
    for s in xst {
        c = c*2 + (s=="1" ? 1 : 0)
    }
    return c
}()
let max: Int = {
    var c = 1
    for _ in 1...n {
        c *= 2
    }
    return c * 2
}()
var memo: [Int?] = Array(repeating: nil, count: max)
/* let pc: Int = { */
/*     let b = String(n, radix: 2) */
/*     var c = 0 */
/*     for d in b { */
/*         if d == "1" { */
/*             c += 1 */
/*         } */
/*     } */
/*     return c */
/* }() */

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



func tpow(_ m: Int) -> Int{
    var a = 1
    if m >= 1 {
        for _ in 1...m {
            a = a << 1
        }
    }
    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 {
    if n == 0 { return 0 }
    if let a = memo[n] { return a }
    let fr = f(n % pc(n)) + 1
    memo[n] = fr
    return fr
    /* var c = 0 */
    /* var n = n */
    /* while n != 0 { */
    /*     n = n % pc(n) */
    /*     c += 1 */
    /* } */
    /* return c */
}
