#include <bits/stdc++.h>
int a[2000000];
int main() {
  int n, i, len;
  long long sum = 0, ans = 0;
  for (scanf("%d", &n), i = 0; i < n; ++i) scanf("%d", a + i);
  std::sort(a, a + n);
  for (i = n - 1, len = 1; i >= 0; --i) {
    sum += a[i];
    if (i + len == n) {
      ans += sum;
      len <<= 2;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
