let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let x = read_line () |> split_string |> List.map int_of_string |> Array.of_list

let rec take res n acc = match (n, acc) with
  | (_, []) | (0, _) -> List.rev res
  | (i, x :: xs) -> take (x :: res) (n - 1) xs
let take = take []

let rec drop n acc = match (n, acc) with
  | (0, acc) -> acc
  | (_, []) -> []
  | (n, x :: xs) -> drop (n - 1) xs

let rec bits_of_int = function
  | 0 -> [0]
  | 1 -> [1]
  | n -> n mod 2 :: (bits_of_int (n / 2))
let bits_of_int n = bits_of_int n |> List.rev

let rec int_of_bits n = function
  | [] -> 0
  | x :: xs -> n * x + int_of_bits (n * 2) xs
let int_of_bits acc = int_of_bits 1 (List.rev acc)

let rec bit_mod x y d =
  if List.length y < d then y
  else 
    let x' = int_of_bits x in
    let y' = int_of_bits (take d y) in
    if y' < x' then bit_mod x y (d + 1)
    else if y' = x' then bit_mod x (drop d y) (List.length x)
    else 
      let next = (bits_of_int (y' - x')) @ (drop d y) in
      bit_mod x next (List.length x)

let rec solve ans acc =
  let t = List.fold_left (+) 0 acc in
  let t' = bits_of_int t in
  let m = bit_mod t' acc (List.length t') in
  let m' = int_of_bits m in
  if m' = 0 then Printf.printf "%d\n" ans
  else solve (ans + 1) m

let () =
  for i = 0 to n - 1 do
    x.(i) <- (x.(i) + 1) mod 2;
    solve 1 (Array.to_list x);
    x.(i) <- (x.(i) + 1) mod 2
  done