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