#include <cstdio>
#include <queue>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    priority_queue<int> que;
    for(int i=0;i<n;i++){
        int num;
        scanf("%d",&num);
        que.push(-num);
    }
    int res=0;
    while(que.size()>1){
        int left1=que.top();
        que.pop();
        int left2=que.top();
        que.pop();


        res=res+left1+left2;
        que.push(left1+left2);

    }
    printf("%d",-res);

}