#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> v;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v.push_back(x);
  }
  long long int z;
  long long int count = 1;
  for (long long int i = 0;; i++) {
    if (n == count) {
      z = i;
      break;
    } else
      count *= 4;
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long int prev = 0;
  long long int end = 1;
  vector<long long int> ans;
  while (prev < n) {
    long long int sum = 0;
    for (long long int j = prev; j < end; j++) sum += v[j];
    ans.push_back(sum);
    sum = 0;
    prev = end;
    end *= 4;
  }
  long long int fin = 0;
  long long int calc = z + 1;
  for (long long int j = 0; j < ans.size(); j++) {
    fin += ans[j] * calc;
    calc--;
  }
  cout << fin;
  return 0;
}
