typedeflonglong LL; structComp { booloperator()(const LL& a, const LL& b)const{ return a > b; } }; priority_queue<LL, deque<LL>, Comp> q;
voidinit(){ LL n, a; while (!q.empty()) q.pop(); scanf("%lld", &n); while (n--) { scanf("%lld", &a); q.push(a); } }
LL run(){ LL ret = 0; LL a, b; while (1) { a = q.top(); q.pop(); if (q.empty()) break; b = q.top(); q.pop(); a += b; ret += a; q.push(a); } return ret; }