#include <bits/stdc++.h>
using namespace std;
int n, a[2000005], i, j;
long long rs;
bool cmp(const int &a, const int &b) { return a > b; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1, cmp);
  for (i = 0; (1 << i) <= n; i += 2)
    for (j = 1; j <= (1 << i); ++j) rs += a[j];
  cout << rs << '\n';
  return 0;
}
