import java.lang.Long.*

inline fun str() = readLine()!!
inline fun int() = str().toInt()
inline fun long() = str().toLong()

inline fun read(d:String = " ") = str().split(d)
inline fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
inline fun list() = list {toLong()}.toLongArray()

inline fun <T> T.print() = this.also(::println)

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val leaf = list()
	val notleaf = LongArray(n+1) {0L}
	val leafsum = LongArray(n+1) {0L}

	fun lim(i:Int) = if(i>=60) Long.MAX_VALUE else 1L shl i

	for(i in n downTo 0) {
		if(leaf[i]+notleaf[i]>lim(i)) {
			println(-1)
			return
		}

		if(i>0) {
			notleaf[i-1] += (leaf[i]+notleaf[i]+1)/2
			leafsum[i-1] += leafsum[i]+leaf[i]
		}
	}

	for(i in 1..n)
		notleaf[i] = min(notleaf[i-1]*2-leaf[i],leafsum[i])

	//	System.err.println(leaf.joinToString())
	//	System.err.println(notleaf.joinToString())
	//	System.err.println(sum.joinToString())
	println(leaf.sum()+notleaf.sum())
}
