#include <stdio.h>

int main(){
   long a[100000],sa[100000],n2,sum;
   int  i,n;

   scanf("%d",&n);
   for (i=0;i<=n;i++) scanf("%ld",&a[i]);
   sa[n]=a[n];
   for (i=n-1;i>=0;i--) sa[i]=sa[i+1]+a[i];
   n2=1;sum=0;
   for (i=0;i<=n;i++) {
      if (sa[i]>n2) sum+=n2;
      else          sum+=sa[i];
      n2=(n2-a[i])*2;
      if (n2<0) {
         puts("-1");
         return 0;
      }
   }
   printf("%ld\n",sum);
   return 0;
}
