Binary Alchemy

AtCoder
IDabc370_b
Time2000ms
Memory256MB
Difficulty
There are $N$ types of elements numbered $1, 2, \ldots, N$. Elements can be combined with each other. When elements $i$ and $j$ are combined, they transform into element $A_{i, j}$ if $i \geq j$, and into element $A_{j, i}$ if $i < j$. Starting with element $1$, combine it with elements $1, 2, \ldots, N$ in this order. Find the final element obtained. ## Constraints * $1 \leq N \leq 100$ * $1 \leq A_{i, j} \leq N$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_{1, 1}$ $A_{2, 1}$ $A_{2, 2}$ $\vdots$ $A_{N, 1}$ $A_{N, 2}$ $\ldots$ $A_{N, N}$ [samples]
Samples
Input #1
4
3
2 4
3 1 2
2 1 2 4
Output #1
2

*   Combining element $1$ with element $1$ results in element $3$.
    
*   Combining element $3$ with element $2$ results in element $1$.
    
*   Combining element $1$ with element $3$ results in element $3$.
    
*   Combining element $3$ with element $4$ results in element $2$.
    

Therefore, the value to be printed is $2$.
Input #2
5
5
5 5
5 5 5
5 5 5 5
5 5 5 5 5
Output #2
5
Input #3
6
2
1 5
1 6 3
2 6 1 4
2 1 1 1 6
5 6 1 2 2 5
Output #3
5
API Response (JSON)
{
  "problem": {
    "name": "Binary Alchemy",
    "description": {
      "content": "There are $N$ types of elements numbered $1, 2, \\ldots, N$. Elements can be combined with each other. When elements $i$ and $j$ are combined, they transform into element $A_{i, j}$ if $i \\geq j$, and ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc370_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ types of elements numbered $1, 2, \\ldots, N$.\nElements can be combined with each other. When elements $i$ and $j$ are combined, they transform into element $A_{i, j}$ if $i \\geq j$, and ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments