/*
类似于传纸条一题
*/
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[11][11],dp[11][11][11][11];
int Max(int t,int h,int m,int y,int l){
return max(t,max(h,max(m,max(y,l))));
}
int main(){
scanf("%d",&n);
int x,y,z;
while(1){
scanf("%d%d%d",&x,&y,&z);
if(x==0&&y==0&&z==0)break;
a[x][y]=z;
}
for(int x1=1;x1<=n;x1++)
for(int y1=1;y1<=n;y1++)
for(int x2=1;x2<=n;x2++)
for(int y2=1;y2<=n;y2++){
int add=0;
if(x1==x2&&y1==y2)add=a[x1][y1];
else add=a[x1][y1]+a[x2][y2];
dp[x1][y1][x2][y2]=Max(dp[x1][y1][x2][y2],dp[x1-1][y1][x2-1][y2],dp[x1-1][y1][x2][y2-1],dp[x1][y1-1][x2-1][y2],dp[x1][y1-1][x2][y2-1])+add;
}
printf("%d",dp[n][n][n][n]);
}