n = int(eval(input()))

a = list(map(int, input().split()))

a_min = [0] * (n + 1)

a_min[n] = a[n]

for i in range(n - 1, -1, -1):

    a_min[i] = a[i] + a_min[i + 1]



b = [1]

for i in range(n):

    tmp = b[i] - a[i]

    b.append(min(tmp * 2, a_min[i + 1]))

    if tmp < 1 or tmp * 2 < a[i + 1]:

        print((-1))

        break

else:

    if n == 0:

        ans = 1 if a[0] == 1 else -1

        print(ans)

    else:

        print((sum(b)))

n = int(eval(input()))

a = list(map(int, input().split()))

a_min = [0] * (n + 1)

a_min[n] = a[n]

for i in range(n - 1, -1, -1):

    a_min[i] = a[i] + a_min[i + 1]



b = [1]

for i in range(n):

    tmp = b[i] - a[i]

    b.append(min(tmp * 2, a_min[i + 1]))

    if tmp < 1:

        print((-1))

        break

else:

    if b[n] != a[n]:

        print((-1))

    else:

        print((sum(b)))

n = int(eval(input()))
a = list(map(int, input().split()))
a_min = [0] * (n + 1)
a_min[n] = a[n]
for i in range(n - 1, -1, -1):
    a_min[i] = a[i] + a_min[i + 1]
b = [1]
for i in range(n):
    tmp = b[i] - a[i]
    b.append(min(tmp * 2, a_min[i + 1]))
    if tmp < 1 or tmp * 2 < a[i + 1]:
        print((-1))
        break
else:
    if n == 0:
        ans = 1 if a[0] == 1 else -1
        print(ans)
    else:
        print((sum(b)))

n = int(eval(input()))
a = list(map(int, input().split()))
a_min = [0] * (n + 1)
a_min[n] = a[n]
for i in range(n - 1, -1, -1):
    a_min[i] = a[i] + a_min[i + 1]
b = [1]
for i in range(n):
    tmp = b[i] - a[i]
    b.append(min(tmp * 2, a_min[i + 1]))
    if tmp < 1:
        print((-1))
        break
else:
    if b[n] != a[n]:
        print((-1))
    else:
        print((sum(b)))

-    if tmp < 1 or tmp * 2 < a[i + 1]: +    if tmp < 1: -    if n == 0: -        ans = 1 if a[0] == 1 else -1 -        print(ans) +    if b[n] != a[n]: +        print((-1))