import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt
    val as = in.readLine().split("\\s+").map(_.toInt)

    val maxes = Array.ofDim[Long](as.length)
    var sum = 0L
    for (i <- maxes.length - 1 to 1 by -1) {
      sum += as(i)
      maxes(i - 1) = sum
    }

    var count = 0L
    var node = 1L
    for (i <- as.indices) {
      if (node < as(i)) {
        out.println(-1)
        out.flush()
        return
      }
      count += Math.min(node, maxes(i) + as(i))
      node = (node - as(i)) * 2
    }

    out.println(count)
    out.flush()
  }
}