N = gets.to_i
X = gets.to_i(2)

popcount = {}
dp = {}
1.upto(N) do |i|
    n = X ^ (1<<(N-i))
    c = 0
    log = []
    while n!=0
        if dp[n] then
            c += dp[n]
            break
        end
        log.unshift(n)
        n %= popcount[n] ||= n.to_s(2).count('1')
        c+=1
    end
    p c
    log.each do |l|
        c -=1
        dp[l] = c
    end
end