#include <bits/stdc++.h>
using namespace std;
int t[2000000];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  long long b = 0, ub = 1, a = (log2(n)) / 2 + 1;
  for (int i = 0; i < n; ++i) cin >> t[i];
  sort(t, t + n);
  for (int i = n - 1; i >= 0; --i) {
    if (n - (i + 1) >= ub) {
      ub <<= 2;
      --a;
    }
    b += t[i] * a;
  }
  cout << b;
  return 0;
}
