#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[100001],s[100002],ans,L=1;
int main(void){
    cin>>n;
    for(int i=0;i<=n;i++){
        cin>>a[i];
    }
    for(int i=n;i>=0;i--){
        s[i]=s[i+1]+a[i];
    }
    for(int i=0;i<=n;i++){
        ans+=L;
        L-=a[i];
        if(L<0){cout<<"-1"<<endl;return 0;}
        L=min(2*L,s[i+1]);
    }
    cout<<ans<<endl;
}
