n = gets.to_i
x = gets.chomp

def f(n, m)
  return 0 if n == 0
  return m[n] unless m[n].nil?
  m[n] = f(n % n.to_s(2).count('1'), m) + 1
end
m = []
n.times do |i|
  xx = x.dup
  xx[i] = x[i] == '1' ? '0' : '1'
  puts f(xx.to_i(2), m)
end
