#include <iostream>
#include <algorithm>
using namespace std;
const int N = 12;
int arr[N][N];
int dp[2 * N][N][N];
int n;
void solve() {
for (int i = 2; i <= 2 * n; i++) {
for (int x1 = 1; x1 <= n; x1++) {
for (int x2 = 1; x2 <= n; x2++) {
int y1 = i - x1; int y2 = i - x2;
int t = arr[x1][y1];
if (x1 != x2) { t += arr[x2][y2]; }
int& x = dp[i][x1][x2];
if(y1>=1 && y1 <=n && y2>=1 && y2<=n){
x = max(x, dp[i - 1][x1 - 1][x2 - 1] + t);
x = max(x, dp[i - 1][x1][x2] + t);
x = max(x, dp[i - 1][x1 - 1][x2] + t);
x = max(x, dp[i-1][x1][x2-1]+t);
}
}
}
}
cout << dp[2 * n][n][n] << endl;
return ;
}
int main()
{
cin >> n;
while (1) {
int a, b, c;
cin >> a >> b >> c;
if (a == 0 && b == 0 && c == 0) { break; }
arr[a][b] = c;
}
solve();
return 0;
}