#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  priority_queue<long long int> pq;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    pq.push(-1 * x);
  }
  if ((pq.size() & 1) == 0) pq.push(0);
  long long ans = 0;
  while (pq.size() > 1) {
    long long int sum = pq.top();
    pq.pop();
    sum += pq.top();
    pq.pop();
    sum += pq.top();
    pq.pop();
    ans -= sum;
    pq.push(sum);
  }
  cout << ans << "\n";
  return 0;
}
