#include<cstdio>
#define For(i,A,B) for(i=(A);i<=(B);++i)
typedef long long ll;
const int N=100050;
int a[N];
ll s[N];
inline ll Min(ll a,ll b){return a<b?a:b;}
int main(){
	int n,i;
	ll ans=0ll,ret=1ll;
	scanf("%d",&n);
	For(i,0,n)scanf("%d",a+i);
	for(i=n;~i;--i)s[i]=s[i+1]+a[i];
	For(i,0,n){
		if(ret<a[i]){
			puts("-1");
			return 0;
		}
		ans+=ret;
		ret=Min(ret-a[i]<<1,s[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}