#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long int arr[n];
  int rows = sqrt(n);
  queue<pair<long long int, long long int> > q[2];
  int ii = 0;
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < rows; j++) {
      cin >> arr[ii];
      q[i % 2].push({arr[ii], arr[ii]});
      ii++;
    }
  }
  int count = 0;
  int temp_row = rows;
  sort(arr, arr + n);
  long long r = 0;
  for (int i = 1; i <= n; i *= 4)
    for (int j = n - i; j < n; ++j) r += arr[j];
  cout << r << endl;
  ;
  int kkk = 0;
  while (kkk) {
    auto temp1 = q[0].front();
    q[0].pop();
    auto temp2 = q[0].front();
    q[0].pop();
    auto temp3 = q[1].front();
    q[1].pop();
    auto temp4 = q[1].front();
    q[1].pop();
    count += 2;
    int dalna;
    if (count <= temp_row) {
      dalna = 0;
    } else if (count >= temp_row) {
      dalna = 1;
      if (count == 2 * temp_row) {
        count = 0;
        temp_row /= 2;
      }
    }
    long long int sum = temp1.first + temp2.first + temp3.first + temp4.first;
    long long int maxi =
        max(temp1.second, max(temp2.second, max(temp3.second, temp4.second)));
    sum += maxi;
    q[dalna].push({sum, maxi});
    if (q[0].size() == 1) {
      cout << q[0].front().first << endl;
      return 0;
    }
  }
  return 0;
}
