#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int n;
int a[100010];
ll ans;

ll f(int d,ll R){
	if(R<a[d]){
		puts("-1");
		exit(0);
	}
	if(d==n){
		ans+=a[d];
		return a[n];
	}
	
	
	ll nex=f(d+1,min((R-a[d])*2,10000000000));
	ll crr=min(R-a[d],nex)+a[d];
	ans+=crr;
	return crr;
}

int main(){
	scanf("%d",&n);
	rep(i,0,n+1)scanf("%d",a+i);
	
	f(0,1);
	printf("%lld",ans);
}