#include <iostream>
#include <queue>
using namespace std;
int main() {
priority_queue <long long> nums;
long long n;
cin >> n;
long long number = 0;
for (int i = 0; i < n; i++) {
cin >> number;
nums.push(-number);
}
long long min_sum = 0;
long long a = 0;
long long b = 0;
while ( !nums.empty() )
{
a = nums.top();
nums.pop();
if (nums.empty()) break;
b = nums.top();
nums.pop();
min_sum -= a+b;
nums.emplace(a+b);
}
cout << " " << min_sum;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cXVldWU+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCXByaW9yaXR5X3F1ZXVlIDxsb25nIGxvbmc+IG51bXM7Cglsb25nIGxvbmcgbjsKCWNpbiA+PiBuOwoJbG9uZyBsb25nIG51bWJlciA9IDA7Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewoJCWNpbiA+PiBudW1iZXI7CgkJbnVtcy5wdXNoKC1udW1iZXIpOwoJfQoJbG9uZyBsb25nIG1pbl9zdW0gPSAwOwoJbG9uZyBsb25nIGEgPSAwOwoJbG9uZyBsb25nIGIgPSAwOwoJd2hpbGUgKCAhbnVtcy5lbXB0eSgpICkKCXsKCQlhID0gbnVtcy50b3AoKTsKCQludW1zLnBvcCgpOwoJCWlmIChudW1zLmVtcHR5KCkpIGJyZWFrOwoJCWIgPSBudW1zLnRvcCgpOwoJCW51bXMucG9wKCk7CgkJbWluX3N1bSAtPSBhK2I7CgkJbnVtcy5lbXBsYWNlKGErYik7CgkJCgl9Cgljb3V0IDw8ICIgIiA8PCBtaW5fc3VtOwoJcmV0dXJuIDA7Cn0=