var
a,b,r:longint;
z:array[1..1000,1..1000]of longint;
begin
assign(input,'numtri.in');
assign(output,'numtri.out');
reset(input);
rewrite(output);
read(r);
for a:=1 to r do
for b:=1 to a do
read(z[a,b]);
for a:=r-1 downto 1 do
for b:=1 to a do
if z[a+1,b]>z[a+1,b+1] then z[a,b]:=z[a,b]+z[a+1,b]
else z[a,b]:=z[a,b]+z[a+1,b+1];
writeln(z[1,1]);
close(input);close(output);
end.