#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> nums;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    nums.push_back(a);
  }
  sort(nums.begin(), nums.end(), greater<int>());
  int maxAppearance = 0;
  while (n / pow(4, maxAppearance) > 1) {
    maxAppearance++;
  }
  maxAppearance++;
  long long ans = 0;
  int powCount = 0;
  int numLevel = pow(4, 0);
  for (int i = 0; i < n; i++) {
    if (numLevel <= 0) {
      powCount++;
      maxAppearance--;
      numLevel = pow(4, powCount) - pow(4, powCount - 1);
    }
    ans += maxAppearance * nums[i];
    numLevel--;
  }
  cout << ans << '\n';
}
