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

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n+1];
  for (long i = 0; i <= n; i++) {
    scanf("%ld", &a[i]);
  }
  if (n == 0) {
    if (a[0] == 1) {
      printf("1\n");
    } else {
      printf("-1\n");
    }
    return 0;
  }
  long max[n+1],rev[n+1];
  max[0] = 1;
  for (long i = 1; i <= n; i++) {
    max[i] = (max[i-1]-a[i-1])*2;
    if (max[i] > pow(10,18)) {
      max[i] = pow(10,18);
    }
    if (max[i] <= 0) {
      printf("-1\n");
      return 0;
    }
  }
  rev[n] = a[n];
  if (rev[n] > max[n]) {
    printf("-1\n");
    return 0;
  }
  for (long i = n-1; i >= 0; i--) {
    rev[i] = rev[i+1]+a[i];
  }
  long ans = 0;
  for (long i = 0; i <= n; i++) {
    if (max[i] < rev[i]) {
      ans += max[i];
    } else {
      ans += rev[i];
    }
  }
  printf("%ld\n", ans);

  return 0;
}