*a,=map(int,[*open(0)][1].split())
c=sum(a)
s=b=1
for a in a:c-=a;b=min(c,b-a<<1);s+=b
print(max(-1,s))
d21e065071e13db1298aa4a3521ca4244403edfd
<mask token>

<mask token>
for a in a:
    c -= a
    b = min(c, b - a << 1)
    s += b
print(max(-1, s))

*a, = map(int, [*open(0)][1].split())
c = sum(a)
s = b = 1
for a in a:
    c -= a
    b = min(c, b - a << 1)
    s += b
print(max(-1, s))

*a,=map(int,[*open(0)][1].split())
c=sum(a)
s=b=1
for a in a:c-=a;b=min(c,b-a<<1);s+=b
print(max(-1,s))