#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+6;
const ll inf=1e15;
int n,a[N];
ll b[N];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<=n;i++) scanf("%d",&a[i]);
    b[0]=1;
    b[0]-=a[0];
    for(int i=1;i<=n;i++)
    {
        b[i]=b[i-1]*2;
        b[i]-=a[i];
        b[i]=min(b[i],(ll)inf);
    }
    for(int i=0;i<=n;i++)
        if(b[i]<0)
    {
        printf("-1\n");return 0;
    }
    ll ans=a[n],sum=a[n];
    for(int i=n-1;i>=0;i--)
    {
        sum=min(sum,b[i])+a[i];
        ans+=sum;
    }
    printf("%lld\n",ans);
}
