{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as IM
import Data.List
import Debug.Trace

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

cum_max :: [Int] -> [Int]
cum_max = tail . scanl' max 0

nextZeta :: Int -> IM.IntMap (Int,Int) -> Int -> IM.IntMap (Int,Int)
nextZeta en im i = foldl' op im [0..en-1]
  where
    op !im !x | testBit x i = IM.adjust (f (im IM.! (clearBit x i))) x im
              | otherwise   = im
      where
{-
        f (q1,q2) (p1,p2) = (r1,r2)
          where r1:r2:_ = sortOn (\p -> -p) [p1,p2,q1,q2]
-}
        f !x !y = let (q1,q2) = x
                      (p1,p2) = y
                  in
                    if p1 >= q1 then
                      if p2 >= q1 then (p1,p2)
                      else (p1,q1)
                    else
                      if q2 >= p1 then (q1,q2)
                      else (q1,p1)

zeta :: Int -> [Int] -> IM.IntMap (Int, Int)
zeta n as = foldl' (nextZeta en) initmap [0..n-1] 
  where
    en = 2^n
    initmap = IM.fromList (zip [0..en-1] [(a,0) | a <- as])

solve :: Int -> [Int] -> [Int]
solve n as = cum_max $ tail $
                  map ((\(p,q)->p+q) . snd) $ IM.toAscList $ zeta n as

main :: IO ()
main = do
  conts <- B.getContents
  let n : as = bsReadInts conts
      answer = solve n as
  putStr (unlines (map show answer))
