import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

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[Long](N+1)
  for (i <- 0 to N) {
    A(i) = in.next().toLong
  }

  //
  var flag = true
  val dpMax = new Array[Long](N+1)
  var cnt = 1L
  breakable {
    for (i <- 0 to N) {
      cnt -= A(i)
      if (cnt < 0) {
        flag = false
        break
      }

      dpMax(i) = cnt
      cnt = Math.min(cnt * 2, Long.MaxValue / 100)
    }
  }


  if (!flag)
    println(-1)
  else  {
    var ans = 0L
    var nodes = 0L

    breakable {
      for (i <- (0 to N).reverse) {
        val now = A(i)

        nodes = (nodes min dpMax(i)) + now
        ans += nodes
      }
    }

    if (!flag)
      println(-1)
    else
      println(ans)
  }
}

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