#include <bits/stdc++.h>
using namespace std;
int n, a;
int main() {
  ios_base::sync_with_stdio(0);
  priority_queue<long long, vector<long long>, greater<long long> > pq;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    pq.push(a);
  }
  long long ans = 0;
  while (pq.size() != 1) {
    int lp = pq.size() % 2 ? 3 : 2;
    long long nxt = 0;
    for (int i = 0; i < lp; ++i) {
      nxt += pq.top();
      pq.pop();
    }
    ans += nxt;
    pq.push(nxt);
  }
  cout << ans << endl;
  return 0;
}
