#abc370b. B - Binary Alchemy

B - Binary Alchemy

Score : 200200 points

问题陈述

NN 种元素,编号为 1,2,,N1, 2, \ldots, N

元素可以相互结合。当元素 iijj 结合时,如果 iji \geq j,则它们转化为元素 Ai,jA_{i, j};如果 i<ji < j,则转化为元素 Aj,iA_{j, i}

从元素 11 开始,依次与元素 1,2,,N1, 2, \ldots, N 结合。找出最终获得的元素。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There are NN types of elements numbered 1,2,,N1, 2, \ldots, N.

Elements can be combined with each other. When elements ii and jj are combined, they transform into element Ai,jA_{i, j} if iji \geq j, and into element Aj,iA_{j, i} if i<ji < j.

Starting with element 11, combine it with elements 1,2,,N1, 2, \ldots, N in this order. Find the final element obtained.

Constraints

  • 1N1001 \leq N \leq 100
  • 1Ai,jN1 \leq A_{i, j} \leq N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1,1A_{1, 1}

A2,1A_{2, 1} A2,2A_{2, 2}

\vdots

AN,1A_{N, 1} AN,2A_{N, 2} \ldots AN,NA_{N, N}

Output

Print the number representing the final element obtained.

Sample Input 1

4
3
2 4
3 1 2
2 1 2 4

Sample Output 1

2
  • Combining element 11 with element 11 results in element 33.

  • Combining element 33 with element 22 results in element 11.

  • Combining element 11 with element 33 results in element 33.

  • Combining element 33 with element 44 results in element 22.

Therefore, the value to be printed is 22.

Sample Input 2

5
5
5 5
5 5 5
5 5 5 5
5 5 5 5 5

Sample Output 2

5

Sample Input 3

6
2
1 5
1 6 3
2 6 1 4
2 1 1 1 6
5 6 1 2 2 5

Sample Output 3

5
}