#include <bits/stdc++.h>
using namespace std;

const int N = 100005;

int n;
long long a[N], l[N], r[N], ans = 0;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    l[n] = r[n] = a[n];
    for (int i = n - 1; i >= 0; i--) {
        l[i] = (l[i + 1] + 1) / 2;
        r[i] = r[i + 1];
        l[i] += a[i]; r[i] += a[i];
    }
    if (l[0] > 1) {
        return cout << -1, 0;
    }
    long long cur = 1;
    for (int i = 0; i <= n; i++) {
        ans += cur;
        cur = min(r[i + 1], (cur - a[i]) * 2);
    }
    cout << ans;
}
