#include <bits/stdc++.h>
using namespace std;
struct cmp {
  bool operator()(long long a, long long b) { return (a > b); }
};
long long ceil(const long long &a, const long long &b) {
  if (a % b == 0) return a / b;
  return a / b + 1;
}
long long mod = 1000000007;
const long long N = 100005;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n < 3 || n % 2 == 0) {
    cout << "-1";
  } else {
    long long ma = 1, ans = 0;
    for (long long i = n; i > 0; i--) {
      long long z = i;
      ans += a[z];
      if (z % 2) {
        long long x = z - 1;
        x /= 2;
        if (x != 0) {
          a[x] = max(0LL, a[x] - a[z]);
          a[2 * x] = max(0LL, a[2 * x] - a[z]);
        }
        a[z] = 0;
      } else {
        long long y = z / 2;
        a[y] = max(0LL, a[y] - a[z]);
        a[2 * y + 1] = max(0LL, a[2 * y + 1] - a[z]);
        a[z] = 0;
      }
    }
    cout << ans;
  }
  return 0;
}
