x,y,s,n,i1,i2,j1,j2:longint;
a:array [0..11,0..11] of longint;
begin
readln(n);
readln(x,y,s);
while not ((x=0) and (y=0) and (s=0)) do
begin
a[x,y]:=s;
readln(x,y,s);
end;
fillchar(f,sizeof(f),0);
for i1:=1 to n do
for j1:=1 to n do
for i2:=1 to n do
for j2:=1 to n do
begin
f[i1,j1,i2,j2]:=0;
if i1-1>0 then
if (i2-1>0) and (f[i1-1,j1,i2-1,j2]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1-1,j1,i2-1,j2]
else if (j2-1>0) and (f[i1-1,j1,i2,j2-1]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1-1,j1,i2,j2-1];
if j1-1>0 then
if (i2-1>0) and (f[i1,j1-1,i2-1,j2]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1,j1-1,i2-1,j2]
else if (j2-1>0) and (f[i1,j1-1,i2,j2-1]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1,j1-1,i2,j2-1];
if (i1=i2) and (j1=j2) then inc(f[i1,j1,i2,j2],a[i1,j1])
else inc(f[i1,j1,i2,j2],a[i1,j1]+a[i2,j2]);
end;
writeln(f[n,n,n,n]);
end.
for i1:=1 to n do
for j1:=1 to n do
for i2:=1 to n do
for j2:=1 to n do
begin
f[i1,j1,i2,j2]:=0;
if (f[i1-1,j1,i2-1,j2]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1-1,j1,i2-1,j2];
if (f[i1-1,j1,i2,j2-1]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1-1,j1,i2,j2-1];
if (f[i1,j1-1,i2-1,j2]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1,j1-1,i2-1,j2];
if (f[i1,j1-1,i2,j2-1]>f[i1,j1,i2,j2])
then f[i1,j1,i2,j2]:=f[i1,j1-1,i2,j2-1];
if (i1=i2) and (j1=j2) then inc(f[i1,j1,i2,j2],a[i1,j1])
else inc(f[i1,j1,i2,j2],a[i1,j1]+a[i2,j2]);
end;