n=gets.to_i
s=gets.chomp
b=s.to_i(2)
pc=s.count('1')
l=s.length
l.times{|i|
  tpc=pc
  tb=b
  tpc=tpc-1 if s[i]=='1'
  tpc=tpc+1 if s[i]=='0'
  tb=tb-(1<<(l-1-i)) if s[i]=='1'
  tb=tb+(1<<(l-1-i)) if s[i]=='0'
  ans=0
  while tb>0 do
    tb=tb%tpc
    tpc=tb.to_s(2).count('1')
    ans=ans+1
  end
  puts ans
}