#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 5;
int p[maxn], a[maxn], b[maxn];
int n;
void solve() {
  int k;
  for (int i = 0; i <= 14; i++) {
    if (n == p[i]) {
      k = i;
      break;
    }
  }
  long long ans = 0;
  sort(a + 1, a + n + 1);
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      if (i % p[j] == 0) b[i]++;
    }
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; i++) {
    ans += 1LL * a[i] * b[i];
  }
  printf("%I64d\n", ans);
}
int main() {
  p[0] = 1;
  for (int i = 1; i <= 14; i++) {
    p[i] = p[i - 1] * 4;
  }
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    solve();
  }
  return 0;
}
