#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
int apple[10000];
void ksort(int l, int r)//快排
{
if (l == r)return;
int mid = apple[(l + r) / 2];
int i = l, j = r;
int temp;
do
{
while (apple[i] < mid)i++;
while (mid < apple[j])j--;
if (i <= j)
{
temp = apple[i];
apple[i] = apple[j];
apple[j] = temp;
i++;
j--;
}
} while (i <= j);
if (i <= r)ksort(i, r);
if (l <= j)ksort(l, j);
return;
}
int main()
{
freopen("fruit.in","r",stdin);
freopen("fruit.out","w",stdout);
int ans = 0;//花费力气
int n;//堆数
int i, j;
cin >> n;
for (i = 0; i < n; ++i)
cin >> apple[i];
ksort(0, n - 1);
for (i = 0; i < n-1; ++i)
{
ans += apple[i] + apple[i + 1];
apple[i + 1] = apple[i] + apple[i + 1];
apple[i] = 0;
for (j = i + 1; j < n - 1; ++j)
if (apple[j] > apple[j + 1])swap(apple[j], apple[j + 1]);
else break;
}
cout << ans;
return 0;
}