eolymp
bolt
Try our new interface for solving problems
Problems

New operational system

New operational system

Raphael has developed a new operating system. A new file is created in it in two ways: copy a previously created file and add some number to it, or copy a previously created file and delete the last number from it. If the file being copied is empty and a delete operation is applied to it, then an empty file is created again.

At the very beginning Raphael's operating system contains only one empty file "root". File "root" has number 0.

Raphael wants to create files one after another. i-th file can be created in one of two ways:

1) "push id x" - create the copy of file with number id (id < i) and to the end of a new file add number x (0x109). Print the amount of numbers in the newly created file (it has number i).

2) "pop id" - create the copy of file with number id (id < i) and from the new file delete the last number (if it exists). Print the deleted number (or "-1" if it does not exist).

Input

The first line contains the number n (1 < n3 * 105) of created files. The following lines contain ways to create files: i - th line describes one of two ways to create the i - th file.

Output

Each time you create a new file print the desired result.

Time limit 1 second
Memory limit 128 MiB
Input example #65
5
push 0 10
push 1 3
pop 1
push 3 7
pop 3
Output example #65
1
2
10
1
-1
Input example #66
6
push 0 3
push 0 9
push 2 5
pop 2
pop 2
pop 4
Output example #66
1
1
2
9
9
-1
Source 2019 İOİ Selection Round of Azerbaijan team