import kotlin.math.min

fun main() {
//    val builder = StringBuilder()

    val n = readInputLine().toInt()

    val aArr = readInputLine().split(" ").map { it.toLong() }.toLongArray()

    if (n == 0) {
        if (aArr[0] != 1L) {
            println(-1)
        } else {
            println(1)
        }
    } else {
        if (aArr[0] != 0L) {
            println(-1)
            return
        }

        val minArr = LongArray(n + 1)
        val maxArr = LongArray(n + 1)

        minArr[n] = aArr[n]
        maxArr[n] = aArr[n]

        for (i in n - 1 downTo 0) {
            minArr[i] = (minArr[i + 1] + 1L) / 2L + aArr[i]
            maxArr[i] = maxArr[i + 1] + aArr[i]
        }

        val ans = LongArray(n + 1)
        ans[0] = 1L
        var usable = 1L

        for (i in 1..n) {
            if (usable * 2L < minArr[i]) {
                println(-1)
                return
            }
            ans[i] = min(usable * 2L, maxArr[i])
            usable = ans[i] - aArr[i]
        }

        println(ans.sum())
    }

//    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
