#include <bits/stdc++.h>
using namespace std;
long long int ans = 0;
int main() {
  long long int n, i, j, k;
  scanf("%lld", &n);
  long long int ara[n + 2];
  for (int i = 1; i <= n; i++) scanf("%lld", &ara[i]);
  long long int siz = 0;
  long long int x = n;
  while (x) {
    x /= 4, ++siz;
  }
  sort(ara + 1, ara + n + 1);
  reverse(ara + 1, ara + n + 1);
  long long int tot = 0;
  long long int last = 1;
  for (long long int i = 1, k = siz; i <= n; i *= 4ll, k--) {
    long long int p = i - tot;
    for (long long int j = last, l = 1; l <= p; j++, l++) {
      ans += (k * ara[j]);
    }
    last = last + p, tot += p;
  }
  printf("%lld\n", ans);
}
