#include <bits/stdc++.h>
using namespace std;
const long long arr = 3e5;
long long ans = 0;
long long a[arr];
signed main() {
  long long n;
  cin >> n;
  long long sum = 0;
  multiset<long long> setik;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    setik.insert(a[i]);
  }
  long long ans = 0;
  while (setik.size() != 1) {
    if (setik.size() % 2 == 0) {
      long long first = *setik.begin();
      setik.erase(setik.find(first));
      long long second = *setik.begin();
      setik.erase(setik.find(second));
      setik.insert(first + second);
      ans += first + second;
    } else {
      long long first = *setik.begin();
      setik.erase(setik.find(first));
      long long second = *setik.begin();
      setik.erase(setik.find(second));
      long long th = *setik.begin();
      setik.erase(setik.find(th));
      setik.insert(first + second + th);
      ans += first + second + th;
    }
  }
  if (setik.size() != 1) {
    for (auto i : setik) ans += i;
  }
  cout << ans;
}
