#include<stdio.h>

int main(void){
    int N,i,count=0;
    scanf("%d",&N);
    int A[N+1],B[N+1],C[N+1],D[N+1]; //B:葉でない頂点 C:2^N D:消す前の深さNの葉の数
    C[0]=1;
    for(i=0;i<=N;i++){
        scanf("%d",&A[i]);
        count+=(i+1)*A[i];
        if(i!=0) C[i]=2*C[i-1];
    }
    D[N]=A[N];
    for(i=N-1;i>=0;i--){
        D[i]=D[i+1]+A[i];
    }
//    for(i=0;i<=N;i++) printf("%d %d\n",C[i],D[i]);
//    printf("\n");
    if(A[0]!=0 && N!=0){
        printf("-1\n");
        return 0;
    }
    B[N]=0;
    for(i=0;i<=N;i++){
        if(D[i]-A[i]>C[i]){
            count=count-(D[i]-C[i]);
            B[i]=C[i]-A[i];
        }else{
            B[i]=D[i]-A[i];
        }
//        printf("i=%d %d\n",i,B[i]);
        if(i>0 && A[i]>2*B[i-1]){
            printf("-1\n");
            return 0;
        }
        if(i>0 && A[i]+B[i]>2*B[i-1]){
            count=count-(A[i]+B[i]-2*B[i-1]);
            B[i]=B[i]-(A[i]+B[i]-2*B[i-1]);
        }
//        printf("i=%d %d\n",i,B[i]);
//        printf("%d\n",count);
    }
    printf("%d\n",count);
    return 0;
}