#include <iostream> #include <queue> using namespace std; int main() { ios::sync_with_stdio(false); int n,temp,ans; priority_queue<int,vector<int>,greater<int>> pq; while (cin >>n) { ans=0; for(int i=0;i<n;++i) { cin>>temp; pq.push(temp); } while(pq.size()!=1) { int t1=pq.top();pq.pop(); int t2=pq.top();pq.pop(); ans=ans+(t1+t2); pq.push(t1+t2); } cout<<ans<<endl; } } // 64 位输出请用 printf("%lld")