#include<iostream>
using namespace std;
int N;
long A[1<<17],B[1<<17];
int main()
{
	cin>>N;
	for(int i=0;i<=N;i++)cin>>A[i];
	if(N==0)
	{
		if(A[0]==1)cout<<1<<endl;
		else cout<<-1<<endl;
		return 0;
	}
	else if(A[0]>0)
	{
		cout<<-1<<endl;
		return 0;
	}
	B[N]=A[N];
	for(int i=N;i--;)B[i]=B[i+1]+A[i];
	long ans=0,pre=1;
	for(int i=0;i<=N;i++)
	{
		if(pre>B[i])pre=B[i];
		ans+=pre;
		pre-=A[i];
		if(pre<0)
		{
			cout<<-1<<endl;
			return 0;
		}
		pre*=2;
	}
	cout<<ans<<endl;
}
