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