#include <bits/stdc++.h>
using namespace std;
int n, m, tp;
int a[2000002];
int main() {
  scanf("%d", &tp);
  int p = 1, i, j;
  for (i = 0; i <= 100; i++) {
    n++;
    if (p == tp) break;
    p *= 4;
  }
  for (i = 0; i < tp; i++) scanf("%d", &a[i]);
  sort(a, a + tp);
  long long ans = 0;
  p = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < p; j++) ans += (long long)a[tp - j - 1];
    p *= 4;
  }
  printf("%I64d", ans);
}
