#include <bits/stdc++.h>
using namespace std;
int n, a[2000001];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n, greater<int>());
  long long ans = 0;
  for (int d = 1, r = n; r; d++, r /= 4) {
    for (int i = 0; i < r; i++) {
      ans += a[i];
    }
  }
  cout << ans;
  return 0;
}
