import java.util.*;
public class Main {
static final int N = 12;
static int[][] g = new int[N][N];
static int[][][] f = new int[2 * N][N][N];
static int n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = Integer.parseInt(sc.nextLine());
while (true) {
String[] s = sc.nextLine().split(" ");
int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]), c = Integer.parseInt(s[2]);
if (x == 0) break;
g[x][y] = c;
}
int ans = dp();
System.out.println(ans);
}
static int dp() {
int[] dx = {-1, 0, -1, 0}, dy = {-1, -1, 0, 0};
for (int k = 2; k <= 2 * n; k++)
for (int i1 = 1; i1 <= n; i1++)
for (int i2 = 1; i2 <= n; i2++) {
int j1 = k - i1, j2 = k - i2;
if (j1 >= 1 && j1 <= n && j2 >= 1 && j2 <= n) {
int t = g[i1][j1];
if (i1 != i2) t += g[i2][j2];
for (int i = 0; i < 4; i++) {
int x = i1 + dx[i], y = i2 + dy[i];
f[k][i1][i2] = Math.max(f[k][i1][i2], f[k - 1][x][y] + t);
}
}
}
return f[2 * n][n][n];
}
}