#include <bits/stdc++.h>
using namespace std;
long long a[2000005];
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, k, n, t;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1, greater<int>());
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    a[i] += a[i - 1];
  }
  i = 1;
  while (i != n) {
    ans += a[i];
    i *= 4;
  }
  ans += a[i];
  cout << ans;
  return 0;
}
