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