let rec take n = function
  | [] -> []
  | x :: xs ->
      if n = 0 then []
      else x :: take (n - 1) xs

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init (1 lsl n) @@ fun _ ->
    Scanf.scanf "%d " @@ fun a -> a in
  let dp = Array.init (1 lsl n) (fun i -> [i]) in
  for i = 0 to (1 lsl n) - 1 do
    for j = 0 to n - 1 do
      if 0 < i land (1 lsl j) then
        dp.(i) <-
          take 2 @@
          List.sort (fun i j -> compare as_.(j) as_.(i)) @@
          List.sort_uniq compare @@
          dp.(i) @ dp.(i land (lnot (1 lsl j)))
    done
  done;
  let a = Array.map (fun is ->
    List.fold_left ( + ) 0 @@
    List.map (Array.get as_) is) dp in
  for i = 1 to (1 lsl n) - 1 do
    a.(i) <- max a.(i) a.(i - 1);
    Printf.printf "%d\n" a.(i)
  done
