#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define N 1000000

int main (void)
{
    long long a[N], node2[N] = {0}, node0[N] = {0};
    long long n, i, ans = 0;

    scanf("%lld", &n);

    for (i = 0; i < n + 1; i++) {
        scanf("%lld", &(a[i]));
    }

    if (n == 0 && a[0] == 1) {
        puts("1");
        return 0;
    } else if (n == 0 && a[0] != 1) {
        puts("-1");
        return 0;
    }

    if (a[0] != 0 || a[n] == 0) {
        puts("-1");
        return 0;
    }

    node2[0] = (long long)1;
    for (i = 1; i < n + 1; i++) {
        node2[i] = node2[i - 1] * (long long)2 - a[i];
        if (node2[i] > 1000000000000) node2[i] = 1000000000000;

        if (i != n && node2[i] <= 0) {
            puts("-1");
            return 0;
        }

        node0[i] = a[i];
    }

    for (i = n; i > 0; i--) {
        ans += node0[i];
        if (node0[i] < node2[i - 1]) {
            node0[i - 1] += node0[i];
        } else {
            node0[i - 1] += node2[i - 1];
        }
    }

    ans += 1;

    printf("%lld", ans);

    return 0;
}
