#include<iostream>
#include<queue>
using namespace std;
const int N=1010;
int main(){
int n;
cin>>n;
priority_queue<int,vector<int>,greater<int>> heap;
while(n--){
int x;
cin>>x;
heap.push(x);
}
int res=0;
while(heap.size()>1){
int x=heap.top();
heap.pop();
int y=heap.top();
heap.pop();
res+=(x+y);
heap.push(x+y);
}
cout<<res<<endl;
return 0;
}
0.0分
0 人评分