var n,i,ha,hb,ta,tb:longint; tot,k:longint;
a,b:array[0..100000]of longint;
function min(x,y,z:longint):longint;
begin
min:=x;
if y<min then min:=y;
if z<min then min:=z;
end;
procedure rsort(s,e:longint);
var x,r,i,j:longint;
procedure swap(x,y:longint);
var t:integer;
begin
t:=a[x];
a[x]:=a[y];
a[y]:=t;
end;
begin
if s>=e then exit;
i:=s; j:=e;
r:=random(j-i)+s;
swap(i,r);
x:=a[i];
repeat
while (i<j)and(a[j]>x) do dec(j);
if i<j then begin a[i]:=a[j]; inc(i); end;
while (i<j)and(a[i]<x) do inc(i);
if i<j then begin a[j]:=a[i]; dec(j); end;
until i=j;
a[i]:=x;
rsort(1,i-1); rsort(i+1,e);
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n+2 do b[i]:=maxint;
a[n+1]:=maxint; a[n+2]:=maxint;
ha:=1;
hb:=1; tb:=0;
rsort(1,n);
tot:=0;
for i:=1 to n-1 do begin
k:=min(a[ha]+b[hb],a[ha+1]+a[ha],b[hb]+b[hb+1]);
if k=a[ha]+b[hb] then begin
inc(ha); inc(hb);
end;
if k=a[ha]+a[ha+1] then ha:=ha+2;
if k=b[hb]+b[hb+1] then hb:=hb+2;
inc(tb);
b[tb]:=k;
inc(tot,b[tb]);
end;
writeln(tot);
end.