#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
int N;
long long int resp, prefix[2000005];
vector<int> V;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  V.push_back(0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    V.push_back(A);
  }
  sort(V.rbegin(), V.rend());
  for (int i = 0; i < N; i++) {
    prefix[i + 1] = prefix[i] + V[i];
  }
  for (int i = 1; i <= N; i *= 4) {
    resp += prefix[i];
  }
  cout << resp << '\n';
  return 0;
}
