#include <bits/stdc++.h>
using namespace std;
int a[2000000];
long long b;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  const auto read_int = []() {
    int x;
    cin >> x;
    return x;
  };
  int n = read_int();
  for (int i = 0; i < n; i++) a[i] = read_int();
  sort(a, a + n), reverse(a, a + n);
  for (int i = 0, u = 1; u <= n; i++, u <<= 2)
    for (int j = 0, v = n / u; j < v; j++) b += a[j];
  cout << b;
}
