import java.math.BigDecimal

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ")

    var preh = BigDecimal.ONE
    var pret = BigDecimal(a[n])

    val down = arrayOfNulls<BigDecimal>(n+1)
    val up = arrayOfNulls<BigDecimal>(n+1)

    down[0] = preh
    up[n] = pret
    for (i in 1 .. n) {
        val ah = BigDecimal(a[i-1])
        val at = BigDecimal(a[n-i])

        preh =  (preh - ah) * BigDecimal(2)
        down[i] = preh
        up[n-i] = pret + at
        pret += at
    }
    if (preh <= BigDecimal.ZERO || down[n]!! < up[n]!!) {
        println(-1)
    } else {
        var ans = BigDecimal.ZERO
        for (i in 0..n) {
            if (down[i]!! <  up[i]!!) {
                ans += down[i]!!
            } else {
                ans += up[i]!!
            }
        }
        println(ans)
    }
}
