#include <stdio.h>
#include <math.h>
int main (void){
    unsigned int n;
    scanf("%u",&n);
    unsigned long long int ai[n+1];
    unsigned int i = 0;
    long long int ue_eda = 1;
    long long int sum_reaf = 0;
    long long int sum_top = 0;
    long long int nokori_reaf = 0;
    for(i = 0;i<=n;i++)    scanf("%llu",&ai[i]);
    if(ai[0] == 1 && n == 0){
        printf("1");
        return 0;
    }

    if(ai[0] != 0) {
        printf("-1");
        return 0;
    }
    for(i = 0;i<=n;i++,ue_eda *= 2){
        ue_eda -= ai[i];
        sum_reaf += ai[i];
        if(ue_eda < 0){
            printf("-1");
            return 0;
        }
    }

    nokori_reaf = sum_reaf;
    ue_eda = 1;
    for(i=0;i<=n;i++,ue_eda *= 2){
        if(nokori_reaf > ue_eda) sum_top += ue_eda;
        else sum_top += nokori_reaf;
        nokori_reaf -= ai[i];
        ue_eda -= ai[i];
    }
    printf("%lld",sum_top);

    return 0;
}