← Back to Problems
Dominance Solvable
Medium standard Games & Strategy
Time limit: 4 s per test  ·  Memory: 256 MB

Two players play a zero-sum game on an n x n payoff matrix A. Simultaneously, the row player picks a row i and the column player picks a column j; the column player then pays the row player A[i][j] — the row player wants the entry to be large, the column player wants it to be small.

A row r is strictly dominated if some other row r' still in the game satisfies A[r'][j] > A[r][j] for every column j still in the game. A column c is strictly dominated if some other column c' still in the game satisfies A[i][c'] < A[i][c] for every row i still in the game.

The game is guaranteed to be dominance-solvable: repeatedly deleting strictly dominated rows and columns (in any order, for either player) always terminates with exactly one cell remaining.

Output that cell: its row index and column index (both 1-based, referring to the original matrix), and its payoff.

Input

The first line contains the integer n. Each of the next n lines contains n integers; the j-th integer on the i-th of these lines is A[i][j].

Output

Three integers separated by spaces: the surviving row index, the surviving column index, and the surviving payoff.

Constraints

1 <= n <= 500

|A[i][j]| <= 10^6

Example

Input:

3
6 7 10
1 2 4
7 10 10

Output:

3 1 7

Row 2 is strictly dominated by row 1 and deleted; columns 2 and 3 are strictly dominated by column 1 and deleted. Among the remaining cells, row 3 now strictly dominates row 1 (7 > 6 in the only remaining column), leaving the single cell (3, 1) with payoff 7.

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Examples

input
3
6 7 10
1 2 4
7 10 10
output
3 1 7
input
2
5 6
3 4
output
1 1 5
input
4
-5 -8 -10 -8
-10 -6 -10 -6
-5 -7 -9 -8
-3 -4 -7 -4
output
4 3 -7
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2