#include<bits/stdc++.h>
using namespace std;
long long n,c,i,a[100008],b[100008];
int main() {
    for(scanf("%lld",&n); i<=n; scanf("%lld",a+i++));
    for(c=1; i--; b[i]=a[i]+b[i+1],a[i]+=a[i+1]+1>>1);
    if(a[0]!=1)
        printf("-1\n"),exit(0);
    for(i=0; i++<n; c+=a[i]=min(a[i-1]<<1,b[i]),a[i]+=b[i+1]-b[i])
        if((a[i-1]+a[i-1])<a[i])
            printf("-1\n"),exit(0);
    printf("%lld\n",c),exit(0);
}