#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m = (long long)(1e9 + 7)) {
  return (n % m + m) % m;
}
inline long long gcd(long long a, long long b) {
  return (b == 0LL) ? a : gcd(b, a % b);
}
inline long long modPow(long long a, long long b,
                        long long m = (long long)(1e9 + 7)) {
  long long ret = 1LL;
  while (b > 0LL) {
    if (b & 1) ret = mod(ret * a, m);
    a = mod(a * a, m);
    b >>= 1;
  }
  return ret;
}
inline bool leapYear(int year) {
  return (year % 400 == 0) || (year % 100 != 0 && year % 4 == 0);
}
long long a[2000006];
int main() {
  int N;
  cin >> N;
  for (int i = (0); i < ((N)); i++) cin >> a[i];
  sort(a, a + N);
  reverse(a, a + N);
  for (int i = (1); i < (N); i++) a[i] += a[i - 1];
  long long ans = 0LL;
  for (int i = 1; i <= N; i <<= 2) ans += a[i - 1];
  cout << ans << endl;
  return 0;
}
