program cogs80;
var
f:array[0..101,0..101] of longint;
st:array[0..100]of longint;
i,j,n,k,len:longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
begin
assign(input,'shizi.in');reset(input);
assign(output,'shizi.out');rewrite(output);
readln(n); readln(st[1]);
for i:=2 to n do begin
readln(j); st[i]:=st[i-1]+j;end;
for len:=2 to n do begin
for i:=1 to n-len+1 do begin
j:=i+len-1;
f[i,j]:=maxlongint;
for k:=i to j-1 do
f[i,j]:=min(f[i,j],f[i,k]+f[k+1,j]+st[j]-st[i-1]);
end;
end;
writeln(f[1,n]);
close(input);close(output);
end.