#include <bits/stdc++.h>
using namespace std;
long long int a[2000001];
int main() {
  ios::sync_with_stdio(false);
  ;
  long long int i, j, n, tempn, sum = 0, ans = 0, cur = 0, x;
  cin >> n;
  tempn = n;
  for (i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (i = 1; i <= tempn; i++) a[i] += a[i - 1];
  while (n) {
    n = n / 4;
    cur++;
  }
  long long int last = 0;
  for (i = 1; i <= tempn; i = i * 4) {
    ans += (a[i] - a[last]) * cur;
    cur--;
    last = i;
  }
  cout << ans;
  return 0;
}
