#include#include #include #include #include using namespace std; int N,R; int x[50100]; int main() { #ifdef xxz freopen("in.txt","r",stdin); #endif // xxz ios::sync_with_stdio(false); cin.tie(0); while(cin>>N) { priority_queue ,greater > P; for(int i = 0; i < N; i++) { cin>>x[i]; P.push(x[i]); } long long ans = 0; while(P.size() > 1) { int L1 = P.top();P.pop(); int L2 = P.top();P.pop(); ans += L1+L2; P.push(L1+L2); } cout<