n=int(eval(input()))

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

tot=sum(a)



v=[1]

for q in a:

    tot-=q

    v.append(min(2*(v[-1]-q),tot))

    

if all([u>=0 for u in v]):

    print((sum(v)))

else:

    print((-1))
n,*a=list(map(int,open(0).read().split()))

tot=sum(a)

v=[1]

for q in a:

  tot-=q

  vt=min(2*(v[-1]-q),tot)

  if vt<0:

    print((-1))

    exit()

  v.append(vt)

print((sum(v)))
n = int(eval(input()))
a = list(map(int, input().split()))
tot = sum(a)
v = [1]
for q in a:
    tot -= q
    v.append(min(2 * (v[-1] - q), tot))
if all([u >= 0 for u in v]):
    print((sum(v)))
else:
    print((-1))

n, *a = list(map(int, open(0).read().split()))
tot = sum(a)
v = [1]
for q in a:
    tot -= q
    vt = min(2 * (v[-1] - q), tot)
    if vt < 0:
        print((-1))
        exit()
    v.append(vt)
print((sum(v)))

-n = int(eval(input())) -a = list(map(int, input().split())) +n, *a = list(map(int, open(0).read().split())) -    v.append(min(2 * (v[-1] - q), tot)) -if all([u >= 0 for u in v]): -    print((sum(v))) -else: -    print((-1)) +    vt = min(2 * (v[-1] - q), tot) +    if vt < 0: +        print((-1)) +        exit() +    v.append(vt) +print((sum(v)))