n,i,a[100010];long long p=1,ans=0,b[100010]={};
#define rep(x)for(i=0;i<=x;i++)
main(){
scanf("%d",&n);
rep(n)scanf("%d",&a[i]);
rep(n-1)b[n-1-i]=b[n-i]+a[n-i];
rep(n){ans+=p;p-=a[i];if(p>b[i])break;p<<=1;p=(p>b[i]?b[i]:p);}
if(i<=n)printf("-1");else printf("%lld",ans);
}