#include <bits/stdc++.h>
using namespace std;
bool check(long long int n, long long int pos) { return n & (1LL << pos); }
long long int Set(long long int n, long long int pos) {
  return n = n | (1LL << pos);
}
long long int dp[(1 << 18) + 5][19];
long long int match[(1 << 18) + 5];
long long int bribe[(1 << 18) + 5];
long long int solve(long long int pos, long long int def) {
  long long int &ret = dp[pos][def];
  if (ret != -1) return ret;
  if (bribe[pos] == -1) return ret = 0;
  long long int need = match[def] - pos;
  ret = (1 << 52);
  if (def < 18) ret = solve(pos + 1, def + 1) + bribe[pos];
  if (need > 0) ret = min(ret, solve(pos + 1, def));
  return ret;
}
int main() {
  long long int i, j, k, l, m, n, o, r, q;
  long long int testcase;
  long long int input, flag, tag, ans;
  while (cin >> n) {
    for (i = n - 1; i >= 0; i--) scanf("%lld", &bribe[i]);
    memset(dp, -1, sizeof dp);
    for (i = 1, j = n / 2; i < n; i++, j /= 2) {
      match[i] = match[i - 1] + j;
    }
    ans = solve(0, 0);
    printf("%lld\n", ans);
  }
}
