{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.Bits
import qualified Data.Vector.Unboxed as VU
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 -> VU.Vector (Int,Int) -> Int -> VU.Vector (Int,Int)
nextZeta en v i = VU.fromList $ map op [0..en-1]
  where
    op x | testBit x i = f (v VU.! (clearBit x i)) (v VU.! x)
         | otherwise   = v VU.! x
      where
        f (q1,q2) (p1,p2) =
                    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] -> VU.Vector (Int, Int)
zeta n as = foldl' (nextZeta en) initvec [0..n-1] 
  where
    en = 2^n
    initvec = VU.fromList [(a,0) | a <- as]

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

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