#include <bits/stdc++.h>
using namespace std;
long long int ar[2 * 1000006];
long long int arsum[2 * 1000006];
int main() {
  ios ::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) cin >> ar[i];
  sort(ar, ar + n);
  reverse(ar, ar + n);
  arsum[0] = ar[0];
  for (int i = 1; i <= n - 1; i++) {
    arsum[i] = arsum[i - 1] + ar[i];
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i *= 4) {
    ans += arsum[i - 1];
  }
  cout << ans << endl;
  return 0;
}
