#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, ans = 0;
priority_queue<long long, vector<long long>, greater<long long> > pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 0; i < n; i++) cin >> k, pq.push(k);
  if (n == 1) {
    cout << 0;
    return 0;
  }
  while (!pq.empty()) {
    sum = 0, n = pq.size();
    for (j = 0; j <= 1 + (n & 1) && !pq.empty(); j++) sum += pq.top(), pq.pop();
    if (!pq.empty()) pq.push(sum);
    ans += sum;
  }
  cout << ans << endl;
  return 0;
}
