import Foundation


let N = Int(readLine()!)!
let A = readLine()!.components(separatedBy: " ")

var rootCount = 0
var leafCount = 1
var topCount = 0

for i in 0...N {
    let a = Int(A[i])!
    
    if i == N {
        topCount += a
        break
    } else {
        topCount += leafCount
        rootCount = leafCount
    }
    
    leafCount = (rootCount - a) * 2
    guard leafCount >= 0 else {
        topCount = -1
        break
    }
}

print(topCount)