#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using pcc = pair<char, char>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vc = vector<char>;
using vd = vector<double>;
template <typename T>
T POW(T a, T b) {
  T x = 1;
  while (b) {
    if (b & 1) x *= a;
    a *= a;
    b >>= 1;
  }
  return x;
}
template <typename T>
T mPOW(T a, T b, T M) {
  T x = 1;
  while (b) {
    if (b & 1) x = (x * a) % M;
    a = (a * a) % M;
    b >>= 1;
  }
  return x;
}
template <typename T>
T Sqrt(T a) {
  T x = (T)sqrt(a);
  if ((x + 1) * (x + 1) == a) x++;
  return x;
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long n, ans = 0;
  cin >> n;
  vll ara(n + 1);
  for (int i = (1); i <= (n); i++) cin >> ara[i];
  sort(ara.begin(), ara.end());
  for (int i = (1); i <= (n); i++) ara[i] += ara[i - 1];
  for (ll i = 1; i <= n; i *= 4) {
    ll x = n / i;
    ans += ara[n] - ara[n - x];
  }
  cout << ans << endl;
  return 0;
}
