#include <bits/stdc++.h>
using namespace std;
long long PRIME = 1000000007;
void solve() {
  long long num;
  cin >> num;
  long long n = (long long)log2(num);
  n = n / 2 + 1;
  vector<long long> a(num);
  for (long long i = 0; i < num; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  long long ind = 0;
  long long curr = 1;
  long long ans = 0;
  long long mult = n;
  while (ind < num) {
    for (long long i = 0; i < curr; i++) {
      ans += mult * a[ind];
      ind++;
    }
    if (curr == 1) {
      curr = 3;
    } else {
      curr *= 4;
    }
    mult--;
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
