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