#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long ans = 0;
  int A[300100];
  cin >> n;
  for (int i = n; i > 0; --i) cin >> A[i];
  priority_queue<int> pq;
  int k = 1;
  int r = n / 2;
  pq.push(-A[k]);
  while (pq.top() != 1) {
    ans -= pq.top();
    pq.pop();
    for (int j = 0; j < r; ++j) pq.push(-A[++k]);
    r /= 2;
  }
  cout << ans;
  return 0;
}
