program ex(f1,f2);
type
zn=array [1..20000] of longint;
var
a:zn; f1,f2:text;
total,now:longint; i,j,k,n,m:longint;
answer:longint;
procedure swap(var x,y:longint);
var
temp:longint;
begin
temp:=x;
x:=y;
y:=temp;
end;
procedure insert(num:longint);
var s:longint;
begin
inc(total);
a[total]:=num;
s:=total;
while (s>1) and (a[s]<a[s div 2]) do
begin
swap(a[s],a[s div 2]);
s:=s div 2;
end;
end;
procedure delete;
var s:longint; y:longint;
begin
a[1]:=a[total];
dec(total);
s:=1;
while (s*2<=total) do
begin
if (s*2=total) or (a[s*2]<a[s*2+1])
then y:=s*2
else y:=s*2+1;
if a[s]>a[y]
then
begin
swap(a[s],a[y]);
s:=y
end
else
exit;
end;
end;
begin
assign(f1,'fruit.in'); reset(f1);
assign(f2,'fruit.out'); rewrite(f2);
readln(f1,n);
total:=0;
for i:=1 to n do
begin
read(f1,m);
insert(m);
end;
answer:=0;
for i:=1 to n-1 do
begin
now:=a[1];
delete;
now:=now+a[1];
answer:=answer+now;
delete;
insert(now);
end;
writeln(f2,answer);
close(f1);
close(f2);
end.