import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto n = readNum!long;
  auto a = readNums!long;

  auto left = a.sum;
  long ans = 1;
  long root = 1;
  if(a[0] > 0){
    writeln(-1);
    return;
  }

  foreach(i; 1 .. n+1){
    left -= a[i];
    ans += a[i];
    long k = 2 * root - a[i];
    if(k < 0 || (k == 0 && i != n)){
      writeln(-1);
      return;
    } else if(k > left){
      root = left;
      ans += left;
    } else {
      root = k;
      ans += k;
    }
  }

  writeln(ans);
}
