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