#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n4, i, tmp, qt, curr;
  vector<int> v;
  long long ans = 0, n;
  scanf("%d", &n4);
  for (i = 0; i < n4; i++) {
    scanf("%d", &tmp);
    v.push_back(tmp);
  }
  sort(v.begin(), v.end(), greater<int>());
  n = 1;
  tmp = n4;
  while (tmp / 4) {
    tmp /= 4;
    n++;
  }
  qt = 1;
  ans = 0;
  curr = 0;
  while (curr < n4) {
    for (i = 0; i < qt; i++) ans += v[i + curr] * n;
    curr += qt;
    qt = curr * 4 - curr;
    n--;
  }
  cout << ans << endl;
  return 0;
}
