#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
const int N = 2e6 + 10;
long long int n, a[N];
int cmp(int i, int j) { return i > j; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  clock_t z = clock();
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) a[i] += a[i - 1];
  int i = 1;
  vector<int> v;
  while (i <= n) {
    v.push_back(i);
    i *= 4;
  }
  long long int ans = 0;
  for (auto i : v) ans += a[i];
  cout << ans << endl;
  fprintf(stderr, "Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
  return 0;
}
