// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun filterList(es: List<IndexedValue<Int>>): List<IndexedValue<Int>> {
  val sortedEs = es.toMutableList().sortedByDescending { it.value }
  val output = mutableListOf<IndexedValue<Int>>()
  output.add(sortedEs[0])
  output.add(sortedEs.first { it.index != sortedEs[0].index })
  return output
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(1 shl n)
  val ys = Array(1 shl n , { listOf<IndexedValue<Int>>() })
  ys[0] = listOf(IndexedValue(0, xs[0]))
  ys[1] = listOf(IndexedValue(0, xs[0]), IndexedValue(1, xs[1]))
  for (k in 2 until (1 shl n)) {
    val list = mutableListOf(IndexedValue(k, xs[k]))
    for (i in 0 until 20) {
      if (k or (1 shl i) == k) {
        list.addAll(ys[k - (1 shl i)])
      }
    }
    // println("k: $k list: $list")
    val filtered = filterList(list)
    ys[k] = filtered
  }

  val zs = ys.map { it.sumBy { it.value } }
  val ws = IntArray(1 shl n)
  for (k in 1 until (1 shl n)) {
    ws[k] = Math.max(ws[k - 1], zs[k])
  }

  val output = StringBuilder()
  for (k in 1 until (1 shl n)) {
    output.append(ws[k])
    output.append('\n')
  }

  print(output)
}