#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2e7 + 5;
unsigned long long ans;
int n;
int box[MaxN];
bool cmp(int x, int y) { return x > y; }
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", &box[i]);
    sort(box + 1, box + 1 + n, cmp);
    for (int i = 1; i <= n; i *= 4) {
      unsigned long long sum = 0;
      for (int j = 1; j <= i; j++) sum += box[j];
      ans += sum;
    }
    printf("%lld\n", ans);
    ans = 0;
  }
  return 0;
}
