#include <bits/stdc++.h>
using namespace std;
int n;
int arr[105], minnum, step;
void p(int x, int v) {
  if (x % 2 == 0) {
    arr[x] -= v;
    arr[x / 2] -= v;
    step += v;
  } else {
    arr[x] -= v;
    arr[x - 1] -= v;
    arr[(x - 1) / 2] -= v;
    step += v;
  }
}
void run() {
  if (minnum < 1)
    puts("-1");
  else {
    int i;
    for (i = n; i > 0; i--)
      if (arr[i] > 0) p(i, arr[i]);
    printf("%d\n", step);
  }
}
void get_data() {
  int i;
  step = 0;
  for (i = 1; i <= n; i++) scanf("%d", &arr[i]);
  minnum = (n - 1) / 2;
  if (n % 2 == 0) minnum = -1;
}
int main() {
  while (~scanf("%d", &n)) {
    get_data();
    run();
  }
  return 0;
}
