#include<iostream>
#include<queue>
using namespace std;
int main() {
priority_queue<int,vector<int>,greater<int>>heap;//小根堆
int n;
while(cin>>n){
if(n==0)break;
for(int i=1;i<=n;i++){
int x;
cin>>x;
heap.push(x);
}
int res = 0;
while(!heap.empty()){
int x=heap.top();
heap.pop();
int y=0;
if(!heap.empty()){
y=heap.top();
heap.pop();
}
else break;
heap.push(x+y);
res+=x+y;
}
cout<<res<<endl;
}
return 0;
}



京公网安备 11010502036488号