#include <bits/stdc++.h>
using namespace std;
long long n, i, arr[2000010], sum[2000010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> arr[i];
  sort(arr + 1, arr + n + 1);
  sum[n] = arr[n];
  for (i = n - 1; i > 0; i--) {
    sum[i] = sum[i + 1] + arr[i];
  }
  long long cnt = 0;
  long long ans = 0;
  long long viv = n;
  while (viv > 0) {
    ans += sum[viv];
    cnt++;
    viv = n - pow(4, cnt);
    viv++;
  }
  cout << ans;
}
