#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,m;
    priority_queue<int> Myqueue;
    scanf("%d",&n);
    int wpl=0;
    for(int i=0;i<n;i++){
        scanf("%d",&m);
        Myqueue.push(-1*m);
    }
    while(Myqueue.size()>=2){
        int s1,s2;
        s1 = Myqueue.top();
        Myqueue.pop();
        s2 = Myqueue.top();
        Myqueue.pop();
        wpl+=(s1+s2);
        Myqueue.push(s1+s2);
    }
    printf("%d",-1*wpl);
    return 0;
}