#include <bits/stdc++.h>
using namespace std;

void solve() {
	int n;
	cin >> n;
	vector<int> v(n + 1);
	for (int i = 0; i <= n; i++) {
		cin >> v[i];
	}
	vector<long long> lim(n + 1);
	long long sum = 0;
	for (int i = n; i >= 0; i--) {
		sum += v[i];
		lim[i] = sum;
	}
	long long vert = 1, bot = 1, dep = 0;
	for (int i = 0; i <= n; i++) {
		int x = v[i];
		if (x <= bot) {
			bot -= x;
			bot = min(lim[++dep], bot * 2);
			vert += bot;
		} else {
			cout << "-1\n";
			return;
		}
	}
	cout << vert << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	solve();
	return 0;
}