program fruit(input,output);
var
a:array[1..10000]of longint;
n,i,j,k,l:longint;
max:longint;
p:boolean;
procedure sort(x,y:longint);
var
i,j,k,l:longint;
begin
i:=x;
j:=y;
k:=a[(x+y)div 2];
repeat
while a[i]<k do inc(i);
while a[j]>k do dec(j);
if i<=j then
begin
l:=a[i];
a[i]:=a[j];
a[j]:=l;
inc(i);
dec(j);
end;
until i>j;
if i<y then sort(i,y);
if j>x then sort(x,j);
end;
begin
assign(input,'fruit.in');
reset(input);
assign(output,'fruit.out');
rewrite(output);
readln(n);
for i:=1 to n do
read(a[i]);
sort(1,n);
max:=0;
for i:=1 to n-1 do
begin
l:=a[i]+a[i+1];
max:=max+l;
p:=false;
for j:=i+2 to n do
if l<a[j] then
begin
for k:=i+1 to j-2 do
a[k]:=a[k+1];
a[j-1]:=l;
p:=true;
break;
end;
if p=false then
begin
for k:=i+1 to n-1 do
a[k]:=a[k+1];
a[n]:=l;
end;
end;
writeln(max);
close(input);
close(output);
end.