#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, a[300050];
  bool vis[300050];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < 0) p = i;
  }
  long long res = 0;
  for (int k = n; k > 1; k >>= 1) {
    if (p >= k) break;
    int mp = -1;
    for (int i = k; i <= n; i++)
      if (!vis[i] && (mp < 0 || a[i] < a[mp])) mp = i;
    res += a[mp];
    vis[mp] = 1;
  }
  cout << res << endl;
  return 0;
}
