program fruit;
var
a:array[1..10000]of longint;
t,b:longint;
n,i:integer;
fin,fout:text;
procedure qsort(s,t:longint);
var
i,j,x,temp:longint;
begin
i:=s;
j:=t;
x:=a[(i+j) div 2];
repeat
while a[i]<x do inc(i);
while a[j]>x do dec(j);
if i<=j then
begin
temp:=a[i];
a[i]:=a[j];
a[j]:=temp;
inc(i);
dec(j);
end;
until i>j;
if s<j then qsort(s,j);
if i<t then qsort(i,t);
end;
procedure init;
var
i:integer;
begin
readln(fin,n);
for i:=1 to n do read(fin,a[i]);
qsort(1,n);
end;
procedure insertsort(i:integer);
var
j,y:integer;
k,e:longint;
begin
k:=a[i+1];
y:=i+1;
for j:=i+2 to n do
if k<=a[j] then exit else
begin
a[y]:=a[j];
y:=j;
a[y]:=k;
end;
end;
begin
assign(fin,'fruit.in');
reset(fin);
assign(fout,'fruit.out');
rewrite(fout);
init;
i:=1;
t:=0;
repeat
a[i+1]:=a[i]+a[i+1];
t:=t+a[i+1];
insertsort(i);
inc(i);
until i=n;
writeln(fout,t);
close(fin);
close(fout);
end.