#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  long long ans = 0;
  int pt = n - 1;
  multiset<int> s;
  s.insert(a.back());
  int eat = n / 2;
  while (*s.begin() != -1) {
    ans += *s.begin();
    s.erase(s.begin());
    for (int it = eat; it--;) s.insert(a[--pt]);
    eat /= 2;
  }
  cout << ans << "\n";
  return 0;
}
