#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  int x = 0;
  scanf("%d", &x);
  vector<int> a(x);
  for (int i = 0; i < x; ++i) {
    scanf("%d", &a[i]);
    a[i] *= -1;
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < x; ++i) {
    a[i] *= -1;
  }
  vector<long long> s(x);
  s[0] = a[0];
  for (int i = 1; i < x; ++i) {
    s[i] = s[i - 1] + a[i];
  }
  long long ans = 0;
  for (long long i = 1; i <= x; i *= 4) {
    ans += s[i - 1];
  }
  cout << ans << endl;
  return 0;
}
