#t417. 方格取数

方格取数

Picking Numbers on a Grid

Problem Description

There is an N×NN\times N grid (N≤9)(N\le 9). Some cells contain a positive integer, while others contain 00. As shown in the figure below (see sample):

A person starts from point AA at the top-left corner and can only move down or right, until reaching point BB at the bottom-right corner. Along the way, he can pick up the number in a cell (the cell then becomes 00). This person walks from AA to BB twice. Find 22 such paths so that the sum of the numbers picked is maximized.

Input Format

The first line of input is an integer NN (indicating the N×NN\times N grid). Each of the following lines contains three integers: the first two indicate a position, and the third is the number placed at that position. A single line of 0 indicates the end of input.

Output Format

Output a single integer: the maximum sum obtained along the 22 paths.

Sample Input 1

8
2 3 13
2 6 6
3 5 7
4 4 14
5 2 21
5 6 4
6 3 15
7 2 14
0 0 0

Sample Output 1

67

Constraints

1≤N≤91\le N\le 9.