local mfl = math.floor
local alltask = {}
local stagetask = {}
local a = {}
local tot = 1
local function bdp_prepare(n)
  for i = 1, n do
    tot = tot * 2
    stagetask[i] = {}
  end
  local a0 = io.read("*n")
  for i = 1, tot - 1 do
    a[i] = io.read("*n")
    if a[i] < a0 then
      alltask[i] = {tot, i}
    else
      alltask[i] = {i, tot}
    end
  end
  a[tot] = a0
  a[tot + 1] = 0
  for i = 1, tot - 1 do
    local ti = i
    local cnt = 0
    for j = 1, n do
      if ti % 2 == 1 then
        cnt = cnt + 1
        ti = ti - 1
      end
      ti = mfl(ti / 2)
    end
    table.insert(stagetask[cnt], i)
  end
end

local function bdp_walk(src, dst)
  local l1 = alltask[dst][1]
  local l2 = alltask[dst][2]
  local r1 = alltask[src][1]
  local r2 = alltask[src][2]
  if l1 == r1 or l2 == r1 then r1 = tot + 1 end
  if l1 == r2 or l2 == r2 then r2 = tot + 1 end
  if a[l1] < a[r1] then
    alltask[dst][1] = r1
    if a[l1] < a[r2] then
      alltask[dst][2] = r2
    else
      alltask[dst][2] = l1
    end
  else
    alltask[dst][1] = l1
    if a[l2] < a[r1] then
      alltask[dst][2] = r1
    else
      alltask[dst][2] = l2
    end
  end
end
local function bdp_doall(n)
  for stage = 1, n - 1 do
    local stlen = #stagetask[stage]
    for i_stagetask = 1, stlen do
      local used = stagetask[stage][i_stagetask]
      local mul = 1
      local tmp = used
      for j = 1, n do
        if tmp % 2 == 0 then
          bdp_walk(used, used + mul)
        else
          tmp = tmp - 1
        end
        tmp = mfl(tmp / 2)
        mul = mul * 2
      end
    end
  end
end

local n = io.read("*n")
bdp_prepare(n)
bdp_doall(n)
local prv = 0
for i = 1, tot - 1 do
  local cur = a[alltask[i][1]] + a[alltask[i][2]]
  if cur < prv then cur = prv end
  print(cur)
  prv = cur
end
