#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int n;
ll a[100010];

int main(){
  scanf("%d",&n);
  for(int i=0;i<n+1;i++){
    scanf("%lld",&a[i]);}
  ll flag=1;
  ll fflag[100010]={};
  ll ans =0;
  for(int i=0;i<n+1;i++){
    ans += flag;
    flag -= a[i];
    fflag[i]=flag;
    //printf("%lld\n",flag);
    flag *= 2;
    if(flag<0){
      ans=-1;
      break;}
  }
  //printf("%lld\n",ans);

  if(ans!=-1){
    ll tmp=fflag[n];
    ans -= fflag[n];
  for(int i=n-1;i>=0;i--){
    tmp = fflag[i]-(2*fflag[i]-tmp);
    if(tmp<0) tmp=0;
    ans -= tmp;}}
  
  printf("%lld\n",ans);
  
  return 0;
}
