#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<limits.h> #include<algorithm> #include<queue> #include<vector> #include<set> #include<stack> #include<string> #include<sstream> #include<map> #include<cctype> using namespace std; int main() { int huff[10001],num,index = 0,total = 0; while(scanf("%d",&num)!=EOF) { for(int i=0;i<num;i++) cin>>huff[i]; while(index<num-1) { sort(huff+index,huff+num); //printf("----%d====%d==(((%d==%d---- ",huff[index],index,num,huff[index+1]); huff[num++] = huff[index] + huff[index+1]; total += huff[num-1]; index += 2; } cout<<total<<endl; } }