#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k=2,m,n,p,s,a[200040],b[200040];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(;i<=n;i++)cin>>a[i];
	if(*a)
	{
		if(n||*a>1)cout<<-1;
		else cout<<1;
		return 0;
	}
	for(i=0;i++<n;)
	{
		k-=a[i];
		if(k<0)
		{
			cout<<-1;
			return 0;
		}
		b[i]=k;
		k*=2;
		if(b[i]>100000000000000)
		{
			i++;
			break;
		}
	}
	p=i;
	for(i=n;i;i--)
	{
		if(i<p)m=min(m,b[i]);
		m+=a[i];
		s+=m;
	}
	cout<<s+1;
}