#include <bits/stdc++.h>
using namespace std;
long long int rec(vector<long long int> &a) {
  vector<long long int> A, B, C, D;
  long long int mx = a[0];
  for (long long int i = 0; i + 3 < a.size(); i += 4) {
    A.push_back(a[i]);
    B.push_back(a[i + 1]);
    C.push_back(a[i + 2]);
    D.push_back(a[i + 3]);
    mx = max(mx, max(a[i], max(a[i + 1], max(a[i + 2], a[i + 3]))));
  }
  if (!A.empty())
    return mx + rec(A) + rec(B) + rec(C) + rec(D);
  else
    return mx;
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i <= n - 1; i++) cin >> a[i];
  sort(a.rbegin(), a.rend());
  cout << (rec(a)) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1, test = 0;
  while (t--) {
    solve();
  }
}
