#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int sim(T &a, T b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline int sil(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline T bs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
T mpow(T x, long i) {
  T ans = 1;
  while (i--) ans *= x;
  return ans;
}
const long long INF = 100000000000LL;
const long mol = 1000000007;
const double eps = 1e-6;
const long maxn = 2500000;
long lin[maxn], n, a[maxn];
int main() {
  long i, j, k;
  scanf("%ld", &n);
  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  sort(a, a + n);
  reverse(a, a + n);
  for (i = 1; i <= n; i *= 4) {
    for (j = 0; j < i; j++) lin[j]++;
  }
  long long ans = 0;
  for (i = 0; i < n; i++) {
    ans += (long long)a[i] * (long long)lin[i];
  }
  cout << ans << endl;
  return 0;
}
