#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 18) + 5;
const int inf = 1999999999;
int n;
int a[maxn];
int plc;
void scanff() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) plc = i;
  }
}
int vis[maxn];
void work() {
  int left = n, now = n / 2;
  long long ans = 0;
  for (; plc < left;) {
    int small = inf, pc;
    for (int i = n; i >= left; i--) {
      if (!vis[i] && a[i] < small) {
        small = a[i];
        pc = i;
      }
    }
    vis[pc] = 1;
    ans += a[pc];
    left -= now;
    now = now / 2;
  }
  printf("%lld\n", ans);
}
int main() {
  scanff();
  work();
  return 0;
}
