#include <bits/stdc++.h>
using namespace std;
long long a[2000002];
int main(void) {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  sort(a, a + n, std::greater<int>());
  long long total = 0;
  long long counter = 0;
  long long current = 1;
  for (int i = 0; i < n; i++) {
    if (current == n) {
      break;
    }
    total += a[i];
    counter++;
    if (counter == current) {
      ans += total;
      if (current < n) {
        current = current * 4;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
