#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  priority_queue<long long, vector<long long>, greater<long long> > q;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    q.push(x);
  }
  long long ans = 0;
  if (n % 2 == 0) q.push(0);
  while (q.size() != 1) {
    long long cur_ans = 0;
    for (long long i = 0; i < 3; i++) {
      if (!q.empty()) {
        cur_ans += q.top();
        q.pop();
      }
    }
    q.push(cur_ans);
    ans += cur_ans;
  }
  cout << ans;
  return 0;
}
