import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Int](1 << N)
  for (i <- 0 to (1 << N) - 1)
    A(i) = in.next().toInt


  //
  val dp = Array.fill[(Int, Int)](1 << N)((-1, -1))
  dp(0) = (0, 0)
  dp(1) = (0, 1)
  var ans = A(0) + A(1)
  println(ans)


  import scala.collection.mutable.PriorityQueue

  for (i <- 2 to (1 << N) - 1) {
    val pq = new PriorityQueue[(Int, Int)]
    pq.enqueue(A(i) -> i)

    for (k <- 0 to N) {
      val hoge = i & 1 << k
      if(hoge != 0) {
        val now = i ^ hoge
        val (a, b) = dp(now)
        pq.enqueue(A(a) -> a)
        pq.enqueue(A(b) -> b)
      }
    }

    var lst: List[Int] = Nil
    while(lst.length < 2) {
      val (_, ind) = pq.dequeue
      if(!lst.contains(ind))
        lst = ind :: lst
    }

    dp(i) = (lst(0), lst(1))
    ans = Math.max(ans, lst.map(ind => A(ind)).sum)
    pw.println(ans)
  }
  pw.flush()
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

