#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  priority_queue<long long> pq;
  long long ans = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    pq.push(-t);
  }
  if (!(n & 1)) {
    sum = pq.top();
    pq.pop();
    sum += pq.top();
    pq.pop();
    pq.push(sum);
    ans -= sum;
  }
  while (pq.size() > 1) {
    sum = pq.top();
    pq.pop();
    sum += pq.top();
    pq.pop();
    sum += pq.top();
    pq.pop();
    pq.push(sum);
    ans -= sum;
  }
  cout << ans << endl;
}
