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

def popcount(n)
    n.to_s(2).count('1')
end

def f(n)
    count = 0
    while n != 0
        count += 1
        # p [n,popcount(n)]
        n = n % popcount(n)
    end
    count
end

arr = Array.new(N+1,0)
1.upto(N) do |i|
    arr[i] = 1 + arr[i%popcount(i)]
end

pcount_base = S.count('1')
1.upto(N) do |i|
    pcount = pcount_base + (X[N-i] == 1 ? -1 : 1)
    x = X ^ (1<<N-i)
    puts 1+arr[x%pcount]
end

# 1.upto(128) do |i|
#     p [i, i.to_s(2), popcount(i), i % popcount(i)] if popcount(i) == 5
# end