open Printf;;
open Scanf;;

let max2 (x, y) z = if x < z then (z, x) else if y < z then (x, z) else (x, y);;
    
let () =
  let n = scanf " %d" (fun x -> x) in
  let a = Array.init (1 lsl n) @@ fun x -> scanf " %d" (fun x -> x) in
  let dp = Array.make (1 lsl n) ((-1, -1), (-1, -1)) in
  for i = 0 to (1 lsl n) - 1 do
    dp.(i) <- ((a.(i), i), (-1, -1))
  done;
  for i = 0 to n - 1 do
    for j = 0 to (1 lsl n) - 1 do
      if (j land (1 lsl i)) = 0 then begin
          dp.(j lor (1 lsl i)) <- max2 dp.(j lor (1 lsl i)) (fst dp.(j));
          dp.(j lor (1 lsl i)) <- max2 dp.(j lor (1 lsl i)) (snd dp.(j))
        end
    done;
  done;
  let ans = ref min_int in
  for i = 1 to (1 lsl n) - 1 do
    let (x, _), (y, _) = dp.(i) in
    ans := max !ans (x + y);
    printf "%d\n" !ans
  done;
  
