#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);
  sort(v.rbegin(), v.rend());
  long long ans = 0;
  for (int i = 1; i <= n; i *= 4) {
    ans += accumulate(v.begin(), v.begin() + i, 0LL);
  }
  printf("%lld", ans);
  return 0;
}
