matgame

Time limit: 5s
Memory limit: 256MB
Input:
Output:

John is playing a game on a square matrix of dimensions N×NN\times N. The rows and the columns of the matrix are numbered from 11 to NN. Cell (i,j)(i,j) is the cell located in the jj-th column of the ii-th row. The matrix contains integers in each cell, specifically, the number written in cell (i,j)(i,j) is ai,ja_{i,j}.

The game consists of a sequence of moves of the form:

  • Select a cell (i,j)(i,j).
  • The score of the move is the value ai,ja_{i,j} written in cell (i,j)(i,j).
  • Remove the ii-th row and the jj-th column from the matrix.
  • Repeat the same process until the matrix becomes empty.

The score of the game is defined as the minimum of the scores of the moves. John asks you to determine the maximum possible score of a game that can be played on the given matrix.

Input data

The first line of input contains NN, the number of rows and columns of the matrix.

Each of the next NN lines contains NN numbers. The jj-th number in the ii-th line is the value ai,ja_{i,j}, i.e., the number written in cell (i,j)(i,j).

Output data

Output a single number, representing the maximal possible score achievable in a game.

Constraints and Clarifications

  • 1N1 0001 \leq N \leq 1 \ 000.
  • 0ai,j1090\leq a_{i,j}\leq 10^{9} for each i=1Ni = 1\ldots N and j=1Nj = 1\ldots N.
# Score Restrictions
1 0 Examples.
2 10 N10N \le 10.
3 30 N300N \le 300, 0ai,j10\leq a_{i,j}\leq 1 for each i=1Ni = 1\ldots N and j=1Nj = 1\ldots N.
4 45 N100N \le 100.
5 15 No additional limitations.

Example

stdin

3
8 0 7
5 6 9
1 7 9

stdout

7

Explanation

In the sample case, one possible optimal way of playing the game is as follows:

  • First, select cell (1,1)(1, 1) with the value 88, and remove the first row and the first column. The matrix becomes this:
6979\begin{matrix} 6 & 9 \\ 7 & 9 \end{matrix}
  • Then, select the cell (2,1)(2, 1) of this new matrix with the value 77, and remove the second row and the first column. The matrix will consist of a single value 99.
  • Finally, select the single value 99 in the matrix, and remove it so that the matrix becomes empty.

The score of the game is the minimum of the scores of the moves, which is 77.

Log in or sign up to be able to send submissions!