#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  priority_queue<long long, vector<long long>, greater<long long>> q;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    q.push(x);
  }
  long long sum = 0;
  if (n == 1)
    cout << "0" << endl;
  else {
    if (n % 2 == 0) q.push(0);
    while (q.size() > 1) {
      long long min1 = q.top();
      q.pop();
      long long min2 = q.top();
      q.pop();
      long long min3 = q.top();
      q.pop();
      long long min = min1 + min2 + min3;
      sum += min;
      q.push(min);
    }
    cout << sum << endl;
  }
  return 0;
}
