poj3253
priority_queue<int,vector, less > q; //按照元素从大到小的顺序出队
priority_queue<int,vector, greater > q; //按照元素从小到大的顺序出队
#include<iostream>
#include<queue>
#define ll long long
using namespace std;
priority_queue <ll,vector<ll>,greater<ll> > q;int main(){
int n,i;ll sum,k,p1,p2;while(cin>>n){
sum=0;while(!q.empty()) //先清空q.pop();while(n--){
scanf("%lld",&k);q.push(k);}while(q.size()>1){
p1=q.top(); q.pop();p2=q.top(); q.pop();sum+=p1+p2;q.push(p1+p2);}cout<<sum<<endl;}return 0;
}