{*******************************************}
{* Program Name: Shizi *}
{* Input File: shizi.in *}
{* Output File: shizi.out *}
{* Date: 2008.7.24 *}
{* Programmer: Peng Bo *}
{*******************************************}
program shizi;
type
sz=array[1..100]of longint;
var
n,l:byte;
g:longint;
s:sz;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure input;
var
f:text;
i:byte;
begin
assign(f,'shizi.in');
reset(f);
readln(f,n);
for i:=1 to n do
readln(f,s[i]);
close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure output;
var
f:text;
begin
assign(f,'shizi.out');
rewrite(f);
write(f,g);
close(f);
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
procedure main;
type
jl=record
s:longint;
x:byte;
end;
var
j,k:byte;
t:jl;
begin
for j:=n downto 2 do
begin
t.s:=maxlongint;
for k:=2 to j do
if s[k]+s[k-1]<t.s
then
begin
t.s:=s[k]+s[k-1];
t.x:=k-1;
end;
if s[1]+s[j]>=t.s
then
begin
g:=g+t.s;
s[t.x]:=t.s;
for k:=(t.x+1) to (n-1) do
s[k]:=s[k+1];
end
else
begin
g:=g+s[1]+s[j];
s[1]:=s[1]+s[j];
end;
end;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
begin
g:=0;
input;
main;
output;
end.
{End.}