#include<cstdio>
#include<algorithm>
using namespace std;
long long sum[100010];
int a[100010];
int n;
long long ans;
int main(){
	scanf("%d",&n);
	for (int i=0;i<=n;i++) scanf("%d",&a[i]);
	long long s=1;
	sum[n+1]=0;
	for (int i=n;i>=0;i--) sum[i]=sum[i+1]+a[i];
	for (int i=0;i<=n;i++)
	{
		if (s<=sum[i]) ans+=s;
		else ans+=sum[i];
		s-=a[i];
		if (s<0)
		{
			printf("-1\n");
			return 0;
		}
		s=s+s;
		if (s>=1e13) s=1e13;
	}
	 printf("%lld\n",ans);
}