#include <bits/stdc++.h>
using namespace std;
int cmp(long long a, long long b) { return a > b; }
long long a[2000005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n, cmp);
  int k = n;
  long long ans = 0;
  a[0] = 0;
  for (int i = 1; i <= n; i++) a[i] += a[i - 1];
  while (k > 0) {
    ans += a[k];
    k /= 4;
  }
  printf("%I64d\n", ans);
  return 0;
}
