var
i,j,k,n,a,b,len,temp:longint;
sum:qword;
heap:array[0..10010]of longint;
procedure put(x:longint);
var
son,temp:longint;
begin
inc(len);
heap[len]:=x;
son:=len;
while (son<>1)and(heap[son div 2]>heap[son]) do
begin
temp:=heap[son div 2];
heap[son div 2]:=heap[son];
heap[son]:=temp;
son:=son div 2;
end;
end;
function get:longint;
var
fa,son,temp:longint;
begin
get:=heap[1];
heap[1]:=heap[len];
dec(len);
fa:=1;
while (fa*2<=len) do
begin
if (fa*2+1>len)or (heap[fa*2]<heap[fa*2+1]) then
son:=fa*2
else son:=fa*2+1;
if heap[fa]>heap[son] then
begin
temp:=heap[fa]; heap[fa]:=heap[son]; heap[son]:=temp;
fa:=son;
end
else break;
end;
end;
begin
assign(input,'fruit.in'); reset(input);
assign(output,'fruit.out');rewrite(output);
readln(n);
for i:=1 to n do
begin
read(temp);
put(temp);
end;
for i:=1 to n-1 do
begin
a:=get;
b:=get;
inc(sum,a+b);
put(a+b);
end;
writeln(sum);
close(input);close(output);
end.