#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    for(int n;cin >> n;){
        int *arr = new int[n];
        for(int i=0;i<n;i++)  cin>>arr[i];
        sort(arr,arr+n); 
        int sum=0;
        for(int i=0;i<n-1;i++){ 
            int t = arr[i]+arr[i+1];
            sum+=t;
            arr[i+1]=t;
            sort(arr+i+1,arr+n);
        }
        cout << sum << endl;
    }
    return 0;
}