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

int N;
int suff[100005];
int A[100005];

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  int now = 1, ans = 0;
  for(int i = 0; i <= N; i++) {
    cin >> A[i];
  }
  for(int i = N; i >= 0; i--) {
    suff[i] += suff[i + 1] + A[i];
  }
  for(int i = 0; i <= N; i++) {
    cin >> A[i];
    ans += min(now, suff[i]);
    now -= A[i];
    now *= 2;
    if(now < 0) {
      cout << "-1\n";
      return 0;
    }else if(now > 1e18) now = 1e18;
  }
  cout << ans << "\n";
}
