#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const ll N = 1000005;
priority_queue<ll, vector<ll>, greater<ll> >a;
int main()
{
ll n;
ll c, x, y;
ll k = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> c;
a.push(c);
}
for (int i = 1; i <= n-1 ; i++)
{
x = a.top();
a.pop();
y = a.top();
a.pop();
a.push(x + y);
k += x + y;
}
cout << k;
return 0;
}