#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 1; i <= n; i++) cin >> arr[i];
  if (n % 2 == 0 || n < 3)
    cout << "-1" << endl;
  else {
    int ans = 0, zero = 0;
    for (int i = n; i >= 2; i--) {
      if (arr[i] > 0 && i % 2 == 1) {
        int x = (i - 1) / 2;
        ans += arr[i];
        arr[2 * x] = max(zero, arr[2 * x] - arr[i]);
        arr[x] = max(zero, arr[x] - arr[i]);
        arr[i] = 0;
      }
      if (arr[i] > 0 && i % 2 == 0) {
        int x = i / 2;
        ans += arr[i];
        arr[2 * x + 1] = max(zero, arr[2 * x + 1] - arr[i]);
        arr[x] = max(zero, arr[x] - arr[i]);
        arr[i] = 0;
      }
    }
    ans += arr[1];
    cout << ans << endl;
  }
  return 0;
}
