#include <bits/stdc++.h>
int M[2000000];
bool cmp(const int &A, const int &B) { return A > B; }
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    long long int ans = 0;
    int s = 1;
    for (int i = 1; i < n; i <<= 2, s++)
      ;
    for (int i = 1; i <= n; i++) scanf("%d", &M[i]);
    std::sort(M + 1, M + 1 + n, cmp);
    for (int i = 0; i < s; i++)
      for (int j = 1; j <= (1 << (2 * i)); j++) ans += M[j];
    printf("%lld\n", ans);
  }
  return 0;
}
