#include <bits/stdc++.h>
using namespace std;
vector<int> ar;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, tmp;
  cin >> n;
  ar.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  sort(ar.rbegin(), ar.rend());
  long long int ans = 0;
  long long int sum = 0;
  int curr = 0;
  int req = 1;
  for (int i = 0; i < n; i++) {
    sum += ar[i];
    curr++;
    if (curr == req) {
      ans += sum;
      req *= 4;
    }
  }
  cout << ans << endl;
  return 0;
}
