In this problem you must perform operations on a rooted tree storing integers in each node. There are several operations to handle:
Knowing that the tree initially consists of the root with value , your task is to perform consecutive operations.
Check the Input Format section for a description of how each operation is given in the input, and review the Constraints section to clarify which operations are not allowed for the root node.
The first line contains a single integer, , denoting the number of operations to perform. The subsequent lines each describe a single operation to perform. The operations are coded as follows:
Invalid operations are:
For each operation, output a single line with the value in the current node.
insert child 2
visit child 1
insert right 3
insert right 4
visit child 2
There are operations to handle.
At the beginning, we change the value stored in the root to and then we print it.
After that, we insert a new child of the root with value .
Then, we visit this child and insert a new node with value as its right sibling.
Next, we visit the last inserted node and print its value.
After that, we insert a new node with value as the right sibling of last inserted node.
Then, we delete the current node (the one with value ), so the current node becomes the root.
Next, we visit the second child of the root, which is the last inserted node with value (because we deleted the node with value ).
Finally, we print the value stored in the current node, which is .