#include <bits/stdc++.h>
using namespace std;
long long n, a[2222222], res, k;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  long long l = log2(sqrt(n));
  int o = 0;
  for (int i = 1; i <= 4; i++) res += l * a[++o];
  k = 12;
  for (long long i = l - 1; i >= 1; i--) {
    for (long long j = 1; j <= k; j++) res += i * a[++o];
    k *= 4;
  }
  cout << res + a[1];
  return 0;
}
