#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
int main() {
  int n, m;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i)
    if (a[i] == -1) {
      for (int j = i; j >= 0; --j) a[j] = 0;
      break;
    }
  priority_queue<int, vector<int>, greater<int>> que;
  que.push(a[n - 1]);
  long long ans = 0;
  while (n > 1) {
    m = n / 2;
    ans += que.top();
    que.pop();
    for (int i = n - 2; i > n - 2 - m; --i) que.push(a[i]);
    n >>= 1;
  }
  cout << ans << endl;
}
