#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5 + 5;
int n;
struct node {
  long long val;
  bool operator<(const node &a) const { return val > a.val; }
} a[MAX_N];
int main() {
  scanf("%d", &n);
  for (register int i = n; i >= 1; i--) scanf("%lld", &a[i].val);
  int cur = n / 2, pos = 2;
  priority_queue<node> pq;
  pq.push(a[1]);
  long long ans = 0;
  while (true) {
    int bribe = pq.top().val;
    pq.pop();
    if (bribe == -1) break;
    ans += bribe;
    for (register int i = 1; i <= cur; i++) pq.push(a[pos++]);
    cur /= 2;
  }
  printf("%lld\n", ans);
  return 0;
}
