Problems
Hard-working Student
Hard-working Student
\includegraphics{https://static.e-olymp.com/content/2e/2e7adeb7eeef0f2a73cc52a42fdce2a1e4dd96c1.jpg}
Billy is a hard-working student. He is fond of computers and intends to learn as much as possible. Now he studies graph theory, and must write a program to build the graph which is shown on the Figure.
The vertices of the graph are labeled sequentially with integer keys starting from \textbf{0} to \textbf{N-1} (\textbf{N}≤\textbf{10000}). There are two types of edges: backward edges labeled with \textbf{B} in the Figure (for example from node \textbf{4} to node \textbf{2}, or from node \textbf{3} to node \textbf{1}), and forward edges, labeled with \textbf{F} in the Figure (for example from node \textbf{1} to node \textbf{2} or from node \textbf{0} to node \textbf{3}). Billy’s program starts with an initial graph that contains the vertices \textbf{0}, \textbf{1}, \textbf{2}, \textbf{3}, and must continue to build the graph based on a sequence of commands written in a text file. A command has the following specification:
\textit{index0 string_of_characters index1}
where \textit{index0} and \textit{index1} are the keys of vertices, and \textit{string_of_characters} is a sequence of actions \textbf{executed from right to left}. An action is represented by one of the following characters:
\includegraphics{https://static.e-olymp.com/content/c7/c786116801ce528d111d59873ea6e3a6d726c287.jpg}
where \textbf{v} is the array of the nodes of the graph. The argument of the first operation is the node v\[index1\]. The result of the operations f and b is a node that represents the argument for all the other operations. The operations < and = are the leftmost specified. For example, for the command the action are:
index0 = 4, index1 = 0
x = f(v\[0\]) // forward to node 3, x = 3
y = f(x) // forward creates node (4), y = 4
k(y) // prints the key (4)
V\[4\] = y // put node (4) in array v
A node is put in the array v only by the command <. Initially the array contains the nodes with keys 0, 1, 2, 3, v\[0\]=0, v\[1\]=1,v\[2\]=2and v\[3\]=3. The program input is from a text file. The file contains the sequence of commands. Each print must be to the standard output from the beginning of a line. There are no empty lines in between. White spaces can occur freely in the input. The input data terminate with an end of file.
An input/output sample is in the table bellow.
\includegraphics{https://static.e-olymp.com/content/ec/ecccc4a70faac62de4f5cfd46fd6b538324d8cb1.jpg}
Input example #1
4 <kf 3 0 =bb 4 7 <ff 3
Output example #1
4 =