#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int a[100005];
ll suff[100005];

int main() {
	int n;
	scanf("%d", &n);
	for (int i=0 ; i<=n ; i++) {
		scanf("%d", a+i);
	}
	for (int i=n ; i>=0 ; i--) suff[i] = suff[i+1]+a[i];
	ll num = 1;
	ll sol = 0;
	for (int i=0 ; i<=n ; i++) {
	//	cout <<"num = "<<num<<endl;
		sol += num;
		if (a[i]>num) {
			printf("-1\n");
			return 0;
		}
		num -= a[i];
		num = min(num*2, suff[i+1]);
	}
	printf("%lld\n", sol);
	return 0;
}