#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include<math.h>

int main(){
    int N,i,j,tyou=0,kyoudai,maxk=1;
    int *A;
    scanf("%d",&N);
    A = (int*)malloc(sizeof(int)*(N+1));

    for(i=0;i<N;i++){
        scanf("%d ",&A[i]);
    }
    scanf("%d",&A[i]);

    if(A[0]==1&&N==0){
        tyou = -1;
    }else{
        /*
        for(i=1;i<N;i++){
            tyou += kyoudai;
            kyoudai -= A[i];

            if(kyoudai<0){
                tyou = -1;
                break;
            }

            kyoudai = kyoudai*2;
        }
        tyou+=A[i];
        */
        i=N+1;
        kyoudai = A[i];
        tyou += A[i];
        i--;
        for(i=N;i>-1;i--){
            if(i==0){
                tyou++;
                break;
            }
            for(j=0;j<i;j++){
                maxk*=2;
            }
            maxk -= A[i];
            if(kyoudai/2>maxk){
                tyou = -1;
                break;
            }else if(kyoudai>=maxk){
                kyoudai = maxk+A[i];
                tyou+=kyoudai;
            }else{
                kyoudai = kyoudai+A[i];
                tyou+=kyoudai;
            }
       }
    }
    /*for(i=0;i<N+1;i++){
        printf("%d ",A[i]);
    }*/
    printf("%d\n",tyou);

    return 0;
}