UML Syntax
UML (Unified Modeling Language) is a standardized modeling language used for developing complex object-oriented software projects. One of its components is the activity diagram, which is used to describe the algorithms of behavior for interacting parallel processes.
In its simplest form, an activity diagram can be represented as a scheme consisting of nodes and arcs. Each node corresponds to an activity, while an arc represents the transfer of control between two nodes.
A scheme is considered correct if it consists of nodes of the following five types:
1. State. This node performs an action. It has no more than one arc entering and no more than one arc exiting.
2. Decision. This node has one arc entering and two or more arcs exiting. Each exiting arc corresponds to a condition, and only one condition should be true. Control is transferred along the arc of the true condition.
3. Merge. This node has two or more arcs entering and one exiting. A merge signifies the end of several conditional behavior paths initiated by a decision.
4. Synchronization Bar. This node has one arc entering and at least two exiting. It describes the parallel behavior of the system. When executed, control is transferred along all exiting arcs.
5. Join. This node has two or more arcs entering and one exiting. A join is executed when it receives control from all entering arcs.
Conditional behavior is depicted using decisions and merges, while parallel behavior is depicted using synchronization bars and joins. In a UML scheme, two state nodes are highlighted: the initial and the final. The diagram starts in the initial state and ends in the final one. Each node is reachable from the initial state, and from each node, the final state is reachable. A path is a sequence of nodes in the diagram. The entry of a node is a node where the exiting arc enters the given node. The exit of a node is a node for which the entering arc exits from the given node.
Some combinations of decisions and synchronization bars are difficult or even impossible to interpret on traditional von Neumann computational systems because they can generate a potentially infinite number of parallel paths. Therefore, both the UML standard and most implementations define various constraints on the diagram's structure.
Your task is to write a program that reviews the diagram's description and checks its correctness and compliance with the following constraints:
* Execution paths exiting a synchronization bar cannot pass through the same state, decision, or merge.
* Execution paths exiting a decision cannot pass through the same state, synchronization bar, or join.
* Each decision corresponds to a separate merge, where the various execution paths that began at this decision end.
* Each synchronization bar corresponds to one join, where all execution paths that began at this synchronization bar end.
* The entries and exits of decision, synchronization bar, merge, and join nodes can only be states.
* The entries and exits of states can be any nodes.
* To simplify the diagram, one join can be specified for several synchronization bars, combining all paths of the corresponding synchronization bars.
* Similarly, one common merge can be specified for several decisions.
The activity diagram of the UML language is specified as follows. Each node of the diagram is marked with an integer - the node number. The type of node is indicated by a capital Latin letter:
S - state,
D - decision activity,
M - merge,
B - synchronization bar,
J - join.
An example of a simple activity diagram of the UML language is shown in the figure. In it, 0 is the initial state, 17 is the final state, 2, 10 are synchronization bars, 14 is a join, 5 is a decision, 8 is a merge. All other nodes of the diagram are states.
Input
The first line of the input file specifies an integer N (N <= 10000) - the number of elements in the diagram. The nodes of the diagram are numbered from 0 to N - 1. The initial state is numbered 0, and the final one is numbered (N - 1). In each of the next N lines, the nodes of the diagram are described in order, one per line. The description of one node contains, in the first position of the line, one character - the type of node, and then (depending on the type of node) information about entries and exits may follow. For the initial state, only the exit number is specified, and for the final one - only the entry number. For all states, except the initial and final, the entry number is specified first, and then the exit number. For other types of nodes, additional information is absent.
Output
In the output file, you should print the line CORRECT if the diagram is correct and meets all the constraints specified in the condition. Otherwise, print the line INCORRECT.