#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int n, a[100100];
ll b[100100], c = 0, d;

main(){
    b[0]=1;
    scanf("%d", &n);
    for(int i=0; i<=n; i++){
      /*
        if(b[i]>1000000000000000){
            puts("-1");
            return 0;
        }
      */
        scanf("%d", &a[i]);
        if(a[i] <= b[i]){
            b[i+1] = min(2*(b[i]-a[i]), 100000000000000000);
        }else {
            puts("-1");
            return 0;
        }
    }if(b[n]<(a[n]+1)/2){
        puts("-1");
        return 0;
    }
    ll x = a[n],y=a[n];
    for(int i=n-1; i>=0; i--){
        y=a[i] + min(y, b[i]-a[i]);
        x += y;
    }
    printf("%lld", x);
    return 0;
}