#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long a[maxn];
int main() {
  int n;
  scanf("%d", &n);
  priority_queue<long long, vector<long long>, greater<long long>> que;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    que.push(a[i]);
  }
  if (n == 1) {
    cout << 0 << endl;
  } else {
    if (n % 2 == 0) que.push(0);
    long long ans = 0;
    long long sum = 0;
    while (que.size() > 2) {
      sum = que.top();
      que.pop();
      sum += que.top();
      que.pop();
      sum += que.top();
      que.pop();
      ans += sum;
      que.push(sum);
    }
    cout << ans << endl;
  }
  return 0;
}
