#include <stdio.h>

long long min(long long a,long long b){
  if(a>=b){return b;}
  else{return a;}
}

int main(){
  long long n,ans=1;
  scanf("%lld",&n);
  long long a[n+2],b[n+2],sum[n+2];
  for(long long i=0;i<=n;i++)scanf("%lld",&a[i]);
  
  if(a[0]>0){printf("-1");return 0;}
  
  b[1]=2;
  sum[0]=0;
  
  for(long long i=1;i<=n;i++){
    sum[0]+=a[i];
  }
  
  for(long long i=1;i<=n;i++){
    if(b[n]<a[n]){printf("-1");return 0;}
    
    sum[i]=sum[i-1]-a[i];
    b[n+1]=2*(b[n]-a[n]);
  }
  
  for(long long i=1;i<=n;i++){
    ans+=min(b[i]-a[i],sum[i]);
    ans+=a[i];
  }
  
  printf("%lld",ans);
}
