LCA offline (Easy)
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Initially, there is a tree consisting only of the root (vertex with the number ). You must answer the following queries:
ADD — hang the vertex behind the vertex (it is guaranteed that the vertex already exists).
GET — return LCA of vertices and .
Vertices are numbered from to . We have one tree at a time.
Input
The first line contains the number of queries . The next lines contain the queries themselves. It is guaranteed that the number of queries of each type does not exceed .
Output
For each query of the GET type, print on a separate line one integer — the answer to it.
Examples
Input #1
Answer #1
Submissions 1K
Acceptance rate 57%