#include <bits/stdc++.h>
using namespace std;
int64_t power(int64_t x, int64_t y) {
  int64_t temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int64_t n;
  cin >> n;
  int64_t x = log2(n) / 2, a[n + 1];
  a[0] = 0;
  for (int64_t i = 1; i < n + 1; ++i) cin >> a[i];
  sort(a, a + n + 1);
  int64_t ans = a[n];
  for (int64_t i = 1; i < n + 1; ++i) a[i] += a[i - 1];
  for (int64_t i = 0; i < x; ++i) {
    ans += a[n] - a[n - power(4, i + 1)];
  }
  cout << ans;
}
