#include <stdio.h>
#define N 20000
int count;
int planks[N];
long long get_minimum(void)
{
long long cost = 0;
while( count > 1)
{
int m1 = 0, m2 = 1;
if(planks[m2] < planks[m1])
{
int tmp = m1;
m1 = m2;
m2 = tmp;
}
int i;
for(i = 2; i < count; i++)
{
if(planks[i] < planks[m1])
{
m2 = m1;
m1 = i;
}
else if( planks[i] < planks[m2])
{
m2 = i;
}
}
int t = planks[m1] + planks[m2];
cost+= t;
if( m1 == count-1)
{
int tmp = m1;
m1 = m2;
m2 = tmp;
}
planks[m1] = t;
planks[m2] = planks[count-1];
count--;
}
return cost;
}
int main(void)
{
//freopen("1.txt", "r", stdin);
scanf("%d", &count);
int i;
for(i = 0; i < count; i++)
{
scanf("%d", planks + i);
}
printf("%lld\n", get_minimum());
return 0;
}