let popcnt x =
  let x = (x land 0x5555555555555555) + ((x lsr 1) land 0x5555555555555555) in
  let x = (x land 0x3333333333333333) + ((x lsr 2) land 0x3333333333333333) in
  let x = (x land 0x0f0f0f0f0f0f0f0f) + ((x lsr 4) land 0x0f0f0f0f0f0f0f0f) in
  let x = (x land 0x00ff00ff00ff00ff) + ((x lsr 8) land 0x00ff00ff00ff00ff) in
  let x = (x land 0x0000ffff0000ffff) + ((x lsr 16) land 0x0000ffff0000ffff) in
  (x land 0x00000000ffffffff) + ((x lsr 32) land 0x00000000ffffffff)

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let () = Scanf.scanf "%d\n%s" @@ fun n x ->
  let x = Array.init n @@ String.get x in
  let dp = Array.make (n + 2) 0 in
  for i = 1 to n + 1 do
    dp.(i) <- 1 + dp.(i mod popcnt i)
  done;
  let pop = Array.fold_right (function '0' -> Fun.id | '1' -> succ) x 0 in
  let m0 = Array.fold_left (fun acc c -> (2 * acc + if c = '0' then 0 else 1) mod (pop + 1)) 0 x in
  let m1 =
    if pop = 1
    then 0
    else Array.fold_left (fun acc c -> (2 * acc + if c = '0' then 0 else 1) mod (pop - 1)) 0 x in
  Fun.flip Array.iteri x @@ fun i c ->
    let i = n - i - 1 in
    Printf.printf "%d\n" @@
    if c = '0'
    then 1 + dp.((m0 + power (fun x y -> (x * y) mod (pop + 1)) 1 2 i) mod (pop + 1))
    else if pop = 1
    then 0
    else 1 + dp.((m1 + pop - 1 - power (fun x y -> (x * y) mod (pop - 1)) 1 2 i) mod (pop - 1))