#include <bits/stdc++.h>
using namespace std;
const int N = 10000005;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
long long power(long long b, long long p) {
  long long ret = 1;
  while (p--) ret *= b;
  return ret;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector<long long> num(n);
  for (int i = 0; i < n; i++) cin >> num[i];
  sort(num.rbegin(), num.rend());
  int tn = log2(n);
  long long rp = tn / 2 + 1;
  long long r = num[0] * rp--;
  for (int i = 2; i <= tn; i += 2) {
    for (int j = power(2, i - 2); j < power(2, i); j++) r += num[j] * rp;
    rp--;
  }
  cout << r << endl;
}
