#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  int a[n];
  for (int i = 0; i <= n - 1; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << a[0];
    return;
  }
  sort(a, a + n);
  reverse(a, a + n);
  long long sum = 0;
  for (int m = 1; m <= n; m *= 4) {
    sum += accumulate(a, a + m, 0ll);
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
