#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 20;
long long n, i, j, a[N], ans, p, take;
int main() {
  scanf("%lld", &n);
  p = 1 + log2l(n) / 2;
  for (i = 0; i < n; i++) scanf("%lld", &a[i]);
  sort(a, a + n, greater<long long>());
  n >>= 2LL;
  if (n == 0) return 0 * printf("%lld", a[0]);
  ans = p * a[0] + (p - 1) * (a[1] + a[2] + a[3]);
  if (n == 1) return 0 * printf("%lld", ans);
  p -= 2;
  take = 12;
  i = 4;
  while (p > 0) {
    for (j = i; i < j + take; i++) ans += p * a[i];
    take <<= 2LL;
    p--;
  }
  printf("%lld", ans);
}
