n = gets.to_i
x = gets.chomp

count = x.count('1')
num = x.to_i(2)

$h = {}
$h[0] = 0

def f(a, cnt)
#  puts "#{a} #{cnt}"
  return $h[a] if $h.key?(a)
  b = a % cnt
  $h[a] = f(b, b.to_s(2).count('1')) + 1
end

x.each_char.with_index(1) do |c, i|
  k = 1 << (n - i)
  a = c == '0' ? num + k : num - k
  puts f(a, a.to_s(2).count('1'))
end
