#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = acos(-1.0);
const int inf = (int)1e9;
const double eps = 1e-4;
const int ss = (int)1e6 + 3;
const int base = inf;
bool pred(const pair<int, int>& i, const pair<int, int>& j) {
  if (i.first == j.first) {
    return i.second > j.second;
  } else {
    return i.first > j.first;
  }
}
int a[2000005];
int main() {
  int k;
  scanf("%d", &k);
  long long int res = 0;
  for (int i = 0; i < k; ++i) {
    scanf("%d", &a[i]);
    res += a[i];
  }
  if (k == 1) {
    cout << res;
    return 0;
  }
  sort(a, a + k);
  int z = k / 4;
  while (z != 0) {
    for (int i = k - 1; i >= k - z; --i) {
      res += a[i];
    }
    z /= 4;
  }
  cout << res;
  return 0;
}
