#include <iostream> #include <queue> using namespace std; int main() { int n,ans,a,b,x; while(scanf("%d",&n)!=EOF&&n!=0) { priority_queue<int,vector<int>,greater<int>> myQueue; //优先队列 while(n--) { scanf("%d",&x); myQueue.push(x); } ans = 0; while(myQueue.size()>1) { a=myQueue.top(); myQueue.pop(); b=myQueue.top(); myQueue.pop(); ans+=a+b; myQueue.push(a+b); } printf("%d\n",ans); } return 0; }(•̀ᴗ•́)و