#include <bits/stdc++.h>
using namespace std;
const long long maxN = 2 * (1e6) + 30;
long long n;
long long a[maxN], sum = 0, j, m, h, cur, cnt = 1;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  h = n;
  while (h > 0) {
    m++;
    h /= 4;
  }
  sort(a, a + n);
  reverse(a, a + n);
  while (j < n) {
    for (j; j < cnt; j++) {
      sum += (m - cur) * a[j];
    }
    cnt *= 4;
    cur++;
  }
  cout << sum << endl;
  return 0;
}
