program fruit;
type sz=array[0..20000]of longint;
var que:sz;
i,j,n,eng,sta,fin,tem:longint;
f1:text;
procedure qs(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=que[(l+r) div 2];
repeat
while que[i]<x do
i:=i+1;
while x<que[j] do
j:=j-1;
if i<=j then
begin
y:=que[i];
que[i]:=que[j];
que[j]:=y;
i:=i+1;
j:=j-1;
end;
until i>j;
if l<j then qs(l,j);
if i<r then qs(i,r);
end;
begin
assign(f1,'fruit.in');
reset(f1);
readln(f1,n);
for i:=1 to n do
read(f1,que[i]);
close(f1);
qs(1,n);
sta:=1;
fin:=n;
repeat
if n<>1 then
begin
tem:=que[sta]+que[sta+1];
eng:=eng+tem;
if tem<que[fin] then
begin
for i:=sta+2 to fin do
if que[i]>=tem then
begin
for j:=fin+1 downto i+1 do
que[j]:=que[j-1];
que[i]:=tem;
break;
end
end else que[fin+1]:=tem;
dec(n);
sta:=sta+2;
fin:=fin+1;
end;
until n=1;
assign(f1,'fruit.out');
rewrite(f1);
writeln(f1,eng);
close(f1);
end.