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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n;
	cin >> n;

	int a[100010];
	for(int i = 0;i < n+1;i++) cin >> a[i];

	int sum = 0;
	for(int i = 0;i < n+1;i++){
		sum += a[i];
	}

	int now = 1;

	int ans = 0;
	for(int i = 0;i < n+1;i++){
		ans += now;
		now -= a[i];
		sum -= a[i]; 
		if(now < 0){
			cout << -1 << endl;
			return 0;
		}
		now = min(now*2, sum);
	}

	cout << ans << endl;

	return 0;
}
