#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int n,m;
ll a[100001];
ll b[100001];
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<=n ;i++){
		cin >> a[i];
		if(i!=0) b[i]=min((ll)1e18,b[i-1]*2-a[i]);
		else b[i]=1-a[i];
	}
	ll ans=0;
	ll cur=0;
	for(int i=n; i>=1 ;i--){
		cur+=a[i];
		ans+=cur;
		if(b[i-1]*2<cur) return cout << "-1\n",0;
		cur=min(cur,b[i-1]);
	}
	if(cur+a[0]!=1) cout << "-1\n";
	else cout << ans+1 << endl;
}