#include <bits/stdc++.h>
using namespace std;
priority_queue<long long int> Q;
int main() {
  long long int n;
  long long int temp;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> temp;
    Q.push(-temp);
  }
  if (n % 2 == 0) {
    n++;
    Q.push(0);
  }
  long long int ans = 0;
  while (n != 1) {
    long long int a, b, c;
    a = -1 * Q.top();
    Q.pop();
    b = -1 * Q.top();
    Q.pop();
    c = -1 * Q.top();
    Q.pop();
    ans += a + b + c;
    Q.push(-1 * (a + b + c));
    n -= 2;
  }
  cout << ans << endl;
  return 0;
}
