#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long int> ar(n);
  for (long long int &x : ar) cin >> x;
  sort(ar.begin(), ar.end(), greater<long long int>());
  long long int res = 0;
  for (int i = 1; i <= n; i *= 4) {
    res += accumulate(ar.begin(), ar.begin() + i, 0LL);
  }
  cout << res << "\n";
  return 0;
}
