#include <bits/stdc++.h>
using namespace std;
long long int ara[200005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> ara[i];
  if (n % 2 == 0) ara[n++] = 0;
  priority_queue<long long int> pQ;
  for (int i = 0; i < n; i++) pQ.push(-ara[i]);
  sort(ara, ara + n);
  long long int ans = 0;
  while (pQ.size() > 2) {
    long long int x = -pQ.top();
    pQ.pop();
    long long int y = -pQ.top();
    pQ.pop();
    long long int z = -pQ.top();
    pQ.pop();
    ans += x + y + z;
    pQ.push(-(x + y + z));
  }
  cout << ans << endl;
  return 0;
}
