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