#include<stdio.h>
#define ll long long
ll min(ll a, ll b){return a < b ? a : b;}
int main(){
    int n;
    scanf("%d",&n);
    ll a[n + 1], b[n + 1];
    for(int i = 0; i <= n; i++)
        scanf("%lld",&a[i]);
    b[0] = 1;
    for(int i = 0; i <= n; i++){
        if(b[i] < a[i]){
            puts("-1");
            return 0;
        }
        if(i == n)
            break;
        b[i] -= a[i];
        b[i + 1] = min(1LL << 60 , b[i] * 2);
    }
    ll ans = a[n], now = a[n];
    for(int i = n - 1; i >= 0; i--){
        ans += min(b[i], now) + a[i];
        now += a[i];
    }
    printf("%lld\n",ans);
    return 0;
}