#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	long long int a[100005];
	for (i = 0; i <= n; i++)
		scanf("%lld", &a[i]);
	long long int max[100005], min[100005];
	max[n] = min[n] = a[n];
	for (i = n - 1; i >= 0; i--)
	{
		max[i] = max[i + 1] + a[i];
		min[i] = (min[i + 1] + 1) / 2 + a[i];
	}
	if (min[0] > 1)
	{
		printf("-1\n");
		return 0;
	}
	long long int ans = 0;
	long long int p = 1;
	for (i = 0; i <= n; i++)
	{
		ans += p;
		p = (p - a[i]) * 2;
		if (p > max[i + 1])
			p = max[i + 1];
	}
	printf("%lld\n", ans);
	return 0;
}