#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool cmp(long long a, long long b) { return a > b; }
int main() {
  int n;
  scanf("%d", &n);
  long long arr[n];
  for (int i = 0; i < n; i++) scanf("%lld", arr + i);
  sort(arr, arr + n, cmp);
  int powersOfFour = 4;
  long long ans = 0;
  for (int i = 1; i < n; ++i) arr[i] += arr[i - 1];
  while (powersOfFour <= n) {
    ans += arr[powersOfFour - 1];
    powersOfFour *= 4;
  }
  printf("%lld", ans + arr[0]);
  return 0;
}
