#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
void fastInOut();
long long pwr(long long base, long long power) {
  long long res = 1;
  while (power) {
    if (power & 1) res *= base;
    base *= base;
    power >>= 1;
  }
  return res;
}
int comp_double(double a, double b) {
  if (fabs(a - b) <= 1e-10) return 0;
  return a < b ? -1 : 1;
}
int main() {
  fastInOut();
  int n, x;
  vector<int> v;
  unsigned long long res = 0;
  cin >> n;
  while (n--) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.rbegin(), v.rend());
  for (int i = 1; i <= v.size(); i *= 4)
    for (int k = 0; k < i; k++) res += v[k];
  cout << res;
}
void fastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
