#include <bits/stdc++.h>
using namespace std;
long long a[2000][2000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> b(n);
  for (auto &x : b) cin >> x;
  sort(b.begin(), b.end(), greater<long long>());
  long long l = 0;
  long long total = 0;
  for (long long k = sqrt(n); k >= 1; k /= 2) {
    for (long long i = 0; i < sqrt(n); i += k) {
      for (long long j = 0; j < sqrt(n); j += k) {
        if (a[i][j] == 0) {
          a[i][j] = b[l++];
          total += a[i][j] * (log2(k) + 1);
        }
      }
    }
  }
  printf("%lld\n", total);
}
