#include<bits/stdc++.h>
using namespace std;
int n,a[111111];
long long ans,l[111111],r[111111],cur,x,y;
int main()
{
	scanf("%d",&n);
	for (int i=0;i<=n;i++) scanf("%d",&a[i]);
	l[n]=r[n]=a[n];
	for (int i=n-1;i>=0;i--)
	{
		l[i]=(l[i+1]+1)/2+a[i];
		r[i]=r[i+1]+a[i];
	}
	if (l[0]<=1 && r[0]>=1);
	else 
	{
		printf("-1\n");
		return 0;
	}
	ans=cur=1;
	for (int i=1;i<=n;i++)
	{
		x=cur;y=cur*2;
		y=min(y,r[i]);ans+=y;
		cur=y-a[i];
	}
	printf("%lld\n",ans);
	return 0;
}