#include
using namespace std;
priority_queue
int main()
{
int n,num,sum = 0,first,second;
scanf("%d",&n);
for (int i = 0 ;i < n ;i++)
{
scanf("%d",&num);
q.push(num);
}
while (!q.empty())
{
first = q.top();
q.pop();
second = q.top();
q.pop();
if (!q.empty()) q.push(first+second);
sum += first + second;
}
printf("%d",sum);
return 0;
}