#include<iostream>
#include<cmath>
using namespace std;
int map[9][9];
int walk(int map[9][9],int N,int x1,int y1,int x2,int y2,int sum) {
int M = 0;
if (x1 == x2 && y1 == y2)sum += map[x1][y1];
else sum += map[x1][y1]+ map[x2][y2];
if (x1 == N && y1 == N && x2 == N && y2 == N)return sum;
if (x1 < N && x2 < N)M=max(M, walk(map, N, x1 + 1, y1, x2 + 1, y2, sum));
if (x1 < N && y2 < N)M = max(M, walk(map, N, x1 + 1, y1, x2, y2 + 1, sum));
if (y1 < N && x2 < N)M = max(M, walk(map, N, x1, y1 + 1, x2 + 1, y2, sum));
if (y1 < N && y2 < N)M = max(M, walk(map, N, x1, y1 + 1, x2, y2 + 1, sum));
return M;
}
int main() {
int N;
int M = 0;
cin >> N;
while (1) {
int x, y, socer;
cin >> x >> y >> socer;
if (x == 0 && y == 0 && socer == 0)break;
else map[x][y] = socer;
}
M = walk(map, N-1, 0, 0, 0, 0, 0);
cout << M << endl;
}