#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    vector<long long int> a(n);
    for (long long int i = 0; i < n; i++) cin >> a[i];
    long long k = 0;
    while (n % 4 == 0) {
      k++;
      n /= 4;
    }
    n = (long long int)a.size();
    long long s = 0;
    long long ans = 0, fl = 0;
    sort((a).begin(), (a).end());
    reverse((a).begin(), (a).end());
    for (long long int i = 0; i < n; i++) {
      if (fl == 0) {
        fl = n / pow(4, k);
        fl -= s;
        s += fl;
        k--;
      }
      ans += a[i] * (k + 2);
      fl--;
    }
    cout << ans;
  }
  return 0;
}
