#include <bits/stdc++.h>
using namespace std;
bool cmp(long long int a, long long int b) { return b < a; }
int main() {
  long long int n;
  cin >> n;
  long long int a[n + 1];
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + n + 1, cmp);
  long long int ans = 0;
  a[0] = 0;
  for (int i = 1; i <= n / 4; i++) {
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= n / 4; i = i * 4) {
    ans += a[i];
  }
  for (int i = n / 4; i <= n; i++) {
    ans += a[i];
  }
  cout << ans << endl;
}
