#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 1];
  arr[0] = 0;
  int mx = (n - 1) / 2;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  if (n < 3 || n % 2 == 0) {
    cout << "-1" << endl;
  } else {
    long long count = 0;
    for (int i = mx; i > 0; i--) {
      int two = i * 2;
      int plus = two + 1;
      int sub = (arr[two] <= 0) ? 0 : arr[two];
      sub = (arr[plus] <= 0) ? sub : max(sub, arr[plus]);
      if (i == 1) sub = max(sub, arr[i]);
      count += sub;
      arr[i] -= sub;
    }
    cout << count << endl;
  }
}
