N = gets.to_i
X = gets.chomp

XN = X.to_i(2)
D = X.count('1')

num = 2 ** N
X.each_char do |x|
  num <<= 1
  if x == '0'
    n = XN + num
    d = D + 1
  else
    n = XN - num    
    d = D - 1
  end
  
  cnt = 0
  if n != 0
    n %= d
    cnt += 1
  end
  while n != 0
    n %= n.to_s(2).count('1')
    cnt += 1
  end
  puts cnt
end
