N = 10**5*2
S = '1' * N

N = gets.to_i
S = gets.chomp
P = S.count('1')
X = S.to_i(2)

XP = X % (P + 1)
XM = X % (P - 1)

rp = 1
rm = 1
ans = []
S.reverse.each_char do |s|
  case s
  when '0'
    pc = P + 1
    n = (XP + rp)
  when '1'
    pc = P - 1
    n = (XM - rm + pc)
  end
  rp = rp * 2 % (P+1)
  rm = rm * 2 % (P-1)

  cnt = 0
  if n != 0
    n %= pc
    cnt += 1
    while n != 0
      n %= n.to_s(2).count('1')
      cnt += 1
    end
  end
  ans << cnt
end
puts ans.reverse