import kotlin.math.min

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toLong() }
    val aaR = aa.reversed()

    val nodeSizes = mutableListOf<Pair<Long, Long>>() // min, max
    nodeSizes.add(Pair(aaR[0], aaR[0]))

    for (i in 1..n) {
        val minSize = nodeSizes[0].first/2 + nodeSizes[0].first % 2 + aaR[i]
        val maxSize = nodeSizes[0].second + aaR[i]
        nodeSizes.add(0, Pair(minSize, maxSize))
    }

    if (nodeSizes[0].first != 1L) {
        println(-1)
        return
    }

    var sum = 1L
    var pMax = 1L
    nodeSizes[0] = Pair(1, 1)

    for (i in 1..n) {
        val max = min(nodeSizes[i].second, pMax * 2)
        pMax = max - aa[i]
        sum += max
    }

    println(sum)
}