#include<bits/stdc++.h>
using namespace std;
int f[12][12][12][12],a[12][12];
int m,n,k;
int main()
{ freopen("fgqs.in","r",stdin);
freopen("fgqs.out","w",stdout);
scanf("%d",&n);
while (true)
{ int x,y,z;
scanf("%d%d%d",&x,&y,&z);
if(!x&&!y&&!z) break;
a[x][y]=z;
}
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
for (int k=1;k<=n;k++)
for (int p=1;p<=n;p++)
{ f[i][j][k][p]=max(max(f[i-1][j][k][p-1],f[i-1][j][k-1][p]),max(f[i][j-1][k][p-1],f[i][j-1][k-1][p]));
if (i==k&&j==p) f[i][j][k][p]+=a[i][j];
else f[i][j][k][p]+=a[i][j]+a[k][p];
}
printf("%d",f[n][n][n][n]);
return 0;
}