#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const int N = 12;
int n, w[N][N], ans;
int vis[N][N][N][N];
void dfs(int x1, int x2, int y1, int y2, int val) {
if (x1 > n || y1 > n || x2 > n || y2 > n) return;
if (x1 == n && x2 == n && y1 == n && y2 == n) {
ans = max(ans, val); return;
}
val += w[x1][y1];
if (x1 != x2) val += w[x2][y2];
if (vis[x1][x2][y1][y2] >= val) return;
vis[x1][x2][y1][y2] = val;
dfs(x1 + 1, x2 + 1, y1, y2, val);
dfs(x1 + 1, x2, y1, y2 + 1, val);
dfs(x1, x2 + 1, y1 + 1, y2, val);
dfs(x1, x2, y1 + 1, y2 + 1, val);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
int t1, t2, t3;
while(cin >> t1 >> t2 >> t3, t1 || t2 ||t3)
w[t1][t2] = t3;
memset(vis, -1, sizeof vis);
dfs(1, 1, 1, 1, 0);
cout << ans;
}