#include <bits/stdc++.h>
using namespace std;
priority_queue<int> pq;
int N, A[300100];
long long R;
int main() {
  scanf("%d", &N);
  for (int i = N; i; --i) scanf("%d", &A[i]);
  int k = 1, r = N / 2;
  pq.push(-A[1]);
  for (; pq.top() != 1;) {
    R += -pq.top();
    pq.pop();
    for (int j = 0; j < r; ++j) pq.push(-A[++k]);
    r /= 2;
  }
  printf("%lld\n", R);
}
