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