#include <bits/stdc++.h>
using namespace std;
long long i, j, k, m, n, p, s, a[264000] = {1 << 30};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (; i++ < n;) {
    cin >> a[i];
    if (a[i] < 0) p = i;
  }
  for (; p;) a[p--] = 0;
  for (p = n - 1; p; p >>= 1) {
    for (i = p, m = 0; i++ < n;) {
      if (a[i] < a[m]) m = i;
    }
    s += a[m];
    a[m] = 1 << 30;
  }
  cout << s;
}
