Persistent stack
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Implement the persistent stack.
Input
The first line contains the number of operations n (1 ≤ n ≤ 200000). The line i + 1 describes the operation i:
t m - add to the stack number t (0 ≤ t < i) the number (0 < m ≤ 1000);
t 0 - delete the last element from the stack number t (0 ≤ t < i). It is guaranteed that the stack t is not empty.
The result of operation i, given in the line i + 1, the stack number i is created. Initially you have an empty stack with number zero.
All input numbers are integers.
Output
For each delete operation print the deleted element in a separate line.
Examples
Input #1
Answer #1
Submissions 681
Acceptance rate 36%