#include <bits/stdc++.h>
using namespace std;
vector<long long> L;
int main() {
  int num, n, m;
  scanf("%d", &num);
  int i, j, x;
  n = 1;
  for (i = 1;; i++)
    if (n < num)
      n *= 4;
    else
      break;
  m = i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    L.push_back(x);
  }
  sort(L.begin(), L.end());
  i = 0;
  long long res = 0;
  for (j = 1; j <= m; j++) {
    long long sum = 0;
    for (x = 1; x <= num / 4 * 3; x++) sum += L[i++];
    if (j == m) sum += L[i];
    sum *= j;
    res += sum;
    num /= 4;
  }
  cout << res << endl;
  return 0;
  return main();
}
