#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;

const int maxn = (int)1e5 + 3;
int n, a[maxn];

LL solve() {
	static LL b[maxn];
	b[n] = 0;
	for(int i = n; i > 0; --i)
		b[i - 1] = b[i] + a[i];
	LL ret = 0, cur = 1;
	for(int i = 0; i <= n; ++i) {
		if(cur < a[i])
			return -1;
		ret += cur;
		cur -= a[i];
		if(cur > b[i])
			return -1;
		cur = min(cur << 1, b[i]);
	}
	return !cur ? ret : -1;
}

int main() {
	scanf("%d", &n);
	for(int i = 0; i <= n; ++i)
		scanf("%d", a + i);
	printf("%lld\n", solve());
	return 0;
}