?
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=15;
int n=0,ans[maxn][maxn],dp[maxn][maxn][maxn][maxn];
int dfs(int x,int y,int x2,int y2)
{
if (dp[x][y][x2][y2]!=-1) return dp[x][y][x2][y2];
if (x==n&&y==n&&x2==n&&y2==n) return 0;
int m=0;
//分别从四个方面进行考虑
if (x<n&&x2<n) m=max(m,dfs(x+1,y,x2+1,y2)+ans[x+1][y]+ans[x2+1][y2]-ans[x+1][y]*(x+1==x2+1&&y==y2));
if (x<n&&y2<n) m=max(m,dfs(x+1,y,x2,y2+1)+ans[x+1][y]+ans[x2][y2+1]-ans[x+1][y]*(x+1==x2&&y==y2+1));
if (y<n&&x2<n) m=max(m,dfs(x,y+1,x2+1,y2)+ans[x][y+1]+ans[x2+1][y2]-ans[x][y+1]*(x==x2+1&&y+1==y2));
if (y<n&&y2<n) m=max(m,dfs(x,y+1,x2,y2+1)+ans[x][y+1]+ans[x2][y2+1]-ans[x][y+1]*(x==x2&&y+1==y2+1));
dp[x][y][x2][y2]=m;
return m;
}
int main()
{
cin>>n;
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
for(int k=0;k<=n;k++)
{
for(int q=0;q<=n;q++)
{
dp[i][j][k][q]=-1;
}
}
}
}
while(1)
{
int x=0,y=0,z=0;
cin>>x>>y>>z;
if(x==0&&y==0&&z==0) break;
ans[x][y]=z;
}
cout<<ans[1][1]+dfs(1,1,1,1)<<endl;
return 0;
}