#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0, v; i < n; i++) {
    cin >> v;
    if (v != -1) {
      a.push_back(v);
    } else {
      for (auto &x : a) {
        x = 0;
      }
    }
  }
  long long ans = a.back();
  int ind = n - 3, pow = n >> 1;
  multiset<int> s;
  while (ind >= 0) {
    int i;
    for (i = ind; ind - i + 1 <= pow; i--) {
      s.insert(a[i]);
    }
    ans += *s.begin();
    s.erase(s.begin());
    ind = i;
    pow /= 2;
  }
  cout << ans << endl;
  return 0;
}
