#include <stdio.h>
int main(){
  long N,i,sum,count;
  sum=0;
  scanf("%ld",&N);
  long A[N+1],max[N+1];
  max[0]=1;
  for(i=0;i<N+1;i++){
    scanf("%ld",&A[i]);
    if(i>0) max[i]=(max[i-1]-A[i-1])*2;
    if(A[i]>max[i]){
      printf("-1");
      return 0;
    }
  }
  count=A[N];
  for(i=N;i>-1;i--){
    if(i<N) count=count+A[i];
    if(count>max[i]) count=max[i];
    sum=sum+count;
  }
  printf("%ld",sum);
  return 0;
}