N = gets.to_i
X = gets.chomp.chars

def cnt(n, d)
  return d if n == 0
  wk = (0...n.bit_length).count{|i| n[i] == 1}
  cnt(n % wk, d+1)
end

t = X.count('1')
h, l = t+1, t-1
t = Array.new(2).map{Array.new(N)}
t[0][N-1] = 1 % h
t[1][N-1] = 1 % l
m_h = (X[N-1] == '1' ? 1 : 0)
m_l = (X[N-1] == '1' ? 1 : 0)
(0..(N-2)).reverse_each{|n|
  t[0][n] = (t[0][n+1] << 1) % h
  t[1][n] = (t[1][n+1] << 1) % l
  if X[n] == '1' then
    m_h = (m_h + t[0][n]) % h
    m_l = (m_l + t[1][n]) % l
  end
}
m_l += l

(0...N).each{|n|
  if X[n] == '1' then
    puts cnt((m_l - t[1][n]) % l, 1)
  else
    puts cnt((m_h + t[0][n]) % h, 1)
  end
}
