import sys

input = sys.stdin.readline

from collections import *



N = int(eval(input()))

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

low = [0]*(N+1)

high = [0]*(N+1)

low[N] = A[N]

high[N] = A[N]



if A[N]>2**N:

    print((-1))

    exit()



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

    low[i] = (low[i+1]+1)//2+A[i]

    high[i] = high[i+1]+A[i]

    lim = 2**i

    

    if low[i]>lim:

        print((-1))

        exit()

    

    high[i] = min(high[i], lim)



now = 1

ans = now



#print(low)

#print(high)



for i in range(N):

    now = min(high[i+1], 2*now)

    ans += now

    now -= A[i+1]

    

print(ans)
import sys

input = sys.stdin.readline



N = int(eval(input()))

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

low = [0]*(N+1)

high = [0]*(N+1)

low[N] = A[N]

high[N] = A[N]



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

    low[i] = (low[i+1]+1)//2+A[i]

    high[i] = high[i+1]+A[i]



if not low[0]<=1<=high[0]:

    print((-1))

    exit()



ans = 1

now = 1



for i in range(N):

    now = min(2*(now-A[i]), high[i+1])

    ans += now



print(ans)
import sys

input = sys.stdin.readline
from collections import *

N = int(eval(input()))
A = list(map(int, input().split()))
low = [0] * (N + 1)
high = [0] * (N + 1)
low[N] = A[N]
high[N] = A[N]
if A[N] > 2**N:
    print((-1))
    exit()
for i in range(N - 1, -1, -1):
    low[i] = (low[i + 1] + 1) // 2 + A[i]
    high[i] = high[i + 1] + A[i]
    lim = 2**i
    if low[i] > lim:
        print((-1))
        exit()
    high[i] = min(high[i], lim)
now = 1
ans = now
# print(low)
# print(high)
for i in range(N):
    now = min(high[i + 1], 2 * now)
    ans += now
    now -= A[i + 1]
print(ans)

import sys

input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
low = [0] * (N + 1)
high = [0] * (N + 1)
low[N] = A[N]
high[N] = A[N]
for i in range(N - 1, -1, -1):
    low[i] = (low[i + 1] + 1) // 2 + A[i]
    high[i] = high[i + 1] + A[i]
if not low[0] <= 1 <= high[0]:
    print((-1))
    exit()
ans = 1
now = 1
for i in range(N):
    now = min(2 * (now - A[i]), high[i + 1])
    ans += now
print(ans)

-from collections import * - -if A[N] > 2**N: -    print((-1)) -    exit() -    lim = 2**i -    if low[i] > lim: -        print((-1)) -        exit() -    high[i] = min(high[i], lim) +if not low[0] <= 1 <= high[0]: +    print((-1)) +    exit() +ans = 1 -ans = now -# print(low) -# print(high) -    now = min(high[i + 1], 2 * now) +    now = min(2 * (now - A[i]), high[i + 1]) -    now -= A[i + 1]