#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=1e5+100,INF=1e14;

int a[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    int s=0;
    for(int i=0;i<=n;i++)
        cin>>a[i],s+=a[i];
    int ans=0;
    for(int i=0,cur=1;i<=n;i++,cur=min(cur*2,INF))
    {
//        cout<<i<<" -> "<<cur<<" "<<s<<"\n";
        ans+=min(cur,s);
        cur-=a[i];
        s-=a[i];
        if(cur<0)
            cout<<-1,exit(0);
    }
    cout<<ans;
}
