import Foundation

let N = Int(readLine()!)!
let A = readLine()!.components(separatedBy: " ").map { Int($0)! }

if N == 0 && A[0] != 1 {
    print(-1)
    exit(EXIT_SUCCESS)
}

var minTop = Array<Int>.init(repeating: 0, count: N + 2)
var maxTop = Array<Int>.init(repeating: 0, count: N + 2)

for i in 0...N {
    minTop[N - i] = A[N - i] + lround(Double(minTop[N - i + 1]) / 2.0)
    maxTop[N - i] = A[N - i] + maxTop[N - i + 1]
}

var topCount = 0
for j in 0...N {
    if j == 0 {
        maxTop[0] = 1
    } else {
        let top = (maxTop[j - 1] - A[j - 1]) * 2
        if minTop[j] <= top {
            if top < maxTop[j] {
                maxTop[j] = top
            }
        } else {
            print(-1)
            exit(EXIT_SUCCESS)
        }
    }
    topCount += maxTop[j]
}

print(topCount)
