n,*a=map(int,open(0).read().split());t=sum(a);v=w=1

for q in a:

  if(w:=min(2*(w-q),t:=t-q))<0:exit(print(-1))

  v+=w

print(v)

n,*a=map(int,open(0).read().split());t=sum(a);v=w=1

print(sum([1]+[exit(print(-1)) if(w:=min(2*(w-q),t:=t-q))<0 else w for q in a]))

n, *a = map(int, open(0).read().split())
t = sum(a)
v = w = 1
for q in a:
    if (w := min(2 * (w - q), t := t - q)) < 0:
        exit(print(-1))
    v += w
print(v)

n, *a = map(int, open(0).read().split())
t = sum(a)
v = w = 1
print(
    sum(
        [1]
        + [exit(print(-1)) if (w := min(2 * (w - q), t := t - q)) < 0 else w for q in a]
    )
)

-for q in a: -    if (w := min(2 * (w - q), t := t - q)) < 0: -        exit(print(-1)) -    v += w -print(v) +print( +    sum( +        [1] +        + [exit(print(-1)) if (w := min(2 * (w - q), t := t - q)) < 0 else w for q in a] +    ) +)