#include <bits/stdc++.h>
using namespace std;
int a[2001000];
int Partition(int l, int r) {
  int temp = l + rand() % (r - l);
  swap(a[l], a[temp]);
  int x = a[l], i = l - 1, j = r + 1;
  while (1) {
    do i++;
    while (a[i] < x);
    do j--;
    while (a[j] > x);
    if (i < j)
      swap(a[i], a[j]);
    else
      return j;
  }
}
void QuickSort(int l, int r) {
  if (l < r) {
    int q = Partition(l, r);
    QuickSort(l, q);
    QuickSort(q + 1, r);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  QuickSort(0, n - 1);
  for (int i = 0, j = n - 1; i < j; i++, j--) swap(a[i], a[j]);
  long long k = 0;
  for (int i = 0; pow(4, i) <= n + 1; i++)
    for (int j = 0; j < pow(4, i); j++) k += a[j];
  cout << k << endl;
}
