{*******************************************}
{* Program Name: Fruit *}
{* Input File: fruit.in *}
{* Output File: fruit.out *}
{* Date: 2008.7.23 *}
{* Programmer: Peng Bo *}
{*******************************************}
program fruit;
type
sz=array[1..10000]of word;
var
n:word;
s:sz;
g:longint;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure input;
var
f:text;
i:word;
begin
assign(f,'fruit.in');
reset(f);
readln(f,n);
for i:=1 to n do
read(f,s[i]);
close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure output;
var
f:text;
begin
assign(f,'fruit.out');
rewrite(f);
if n>1
then
write(f,g)
else
write(f,s[1]);
close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure kpx(l,r:word);
var
i,j:word;
x,t:longint;
begin
i:=l;
j:=r;
x:=s[(l+r)div 2];
repeat
while s[i]<x do
inc(i);
while x<s[j] do
dec(j);
if i<=j
then
begin
t:=s[i];
s[i]:=s[j];
s[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if l<j
then
kpx(l,j);
if i<r
then
kpx(i,r);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure cpx(l:word);
var
i,j:word;
t:longint;
begin
t:=s[1];
for i:=1 to l do
if t>s[i+2]
then
s[i]:=s[i+2]
else
begin
s[i]:=t;
j:=i;
break;
end;
for i:=(j+1) to l do
s[i]:=s[i+1];
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure main;
var
i:word;
begin
for i:=(n-1) downto 1 do
begin
s[1]:=s[1]+s[2];
g:=g+s[1];
cpx(i);
end;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
g:=0;
input;
kpx(1,n);
main;
output;
end.
{End.}