Persistent stack#4313

Persistent stack

1 second
128 megabytes
Very easy

Implement the persistent stack.

Input

The first line contains the number of operations (1 \le n \le 200\,000). The line i + 1 describes the operation :

  • — add to the top of stack number (0 \le t < i) the number (0 < m \le 1000);

  • — remove the top element from stack number (0 \le t < i). It is guaranteed that stack is not empty.

The result of operation , described in line i + 1, is the creation of stack number . Initially, there is 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

Example 1

Loading
Loading