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