#include <bits/stdc++.h>
using namespace std;
long long int nos[312345];
priority_queue<long long int> q;
long long int compute(int size) {
  long long int val = 0;
  long long int t1, t2;
  for (int i = 0; i < size; ++i) {
    q.push(nos[i]);
  }
  while (!q.empty()) {
    t1 = q.top();
    q.pop();
    if (q.size() == 0) {
      val += t1;
      break;
    }
    t2 = q.top();
    q.pop();
    val = val + t1 + t2;
    q.push(t1 + t2);
  }
  return val;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &nos[i]);
  }
  printf("%lld\n", compute(n));
}
