The Capability Advanced Machine (CAM) consists of a simple program, an infinitely long paper tape, and a read/write head.
The tape is composed of a long sequence of cells. Each cell can contain one of the symbols $0$–$8$, or it can be empty. For convenience, the symbol $9$ is used to represent an empty cell.
Before the program starts, the tape already contains some symbols; this sequence of symbols is called the input. For example: $100811811081$
The input is always a continuous string of non-empty symbols. Except for the input symbols, all other parts of the tape are empty. The input above is represented on the tape as follows: $\dots 9 \ 9 \ 1 \ 0 \ 0 \ 8 \ 1 \ 1 \ 8 \ 1 \ 1 \ 0 \ 8 \ 1 \ 9 \ 9 \ \dots$
The read/write head always points to one cell on the tape. The program can control the head to move left or right, write a symbol to the tape, or read the symbol in the current cell as a parameter for the program.
When the program starts, the read/write head points to the first non-empty symbol on the tape.
The CAM program is very simple and consists of only three types of instructions:
L
L <symbol C>
This instruction writes the symbol $C$ to the cell pointed to by the read/write head and moves the head one cell to the left. The symbol $C$ can be $0$–$9$ or $?$. $C=9$ means writing an empty symbol to the tape, and $C=?$ means the current symbol on the tape remains unchanged.
R
R <symbol C>
This instruction writes the symbol $C$ to the cell pointed to by the read/write head and moves the head one cell to the right. The symbol $C$ can be $0$–$9$ or $?$. $C=9$ means writing an empty symbol to the tape, and $C=?$ means the current symbol on the tape remains unchanged.
LOOP-END
LOOP <symbol table H>
<loop body>
END <symbol table E>
This is a loop instruction with two symbol tables, $H$ and $E$. A symbol table consists of zero or more symbols from $0$–$9$ and $?$ (where $?$ is a wildcard that matches any symbol). The loop body can contain any valid sequence of zero or more instructions (loops can be nested infinitely).
The execution process is as follows: 1. First, check if the symbol currently under the read/write head is in symbol table $H$ (note that $?$ matches any symbol, so if $H$ contains $?$, the condition is always true). If it is not in $H$, exit the loop; otherwise, continue. Note: If $H$ is empty, the loop body will not execute. 2. Execute the contents of the loop body. 3. After executing the loop body, check if the symbol currently under the read/write head is in symbol table $E$ (similarly, $?$ in $E$ matches any symbol). If it is not in $E$, exit the loop; if it is, jump back to step 1. Note: If $E$ is empty, the condition is never satisfied, and the loop will exit.
Input
The input file camp.in contains a single line representing an arithmetic expression. The expression satisfies:
At most three operators.
At most one multiplication sign.
It may contain one or more pairs of parentheses, but parentheses will not be directly enclosed by other parentheses (e.g., `((a+b))cwill not appear; the correct form is(a+b)c). Note that this does not mean parentheses cannot be nested, e.g.,a+(b+(c+d))` is valid.
Operands in the expression consist only of letters and $1$.
If the $i$-th letter appears in the expression, the $(i-1)$-th letter must also appear. For example, if the expression contains $c$, it must also contain $b$ and $a$.
Assuming the order of operations (parentheses first, then multiplication/division, then addition/subtraction, and left-to-right for equal precedence), you can assume that at any step of the calculation, the value is a positive integer. Expressions like (1-1) will not appear. However, expressions like (a-b) might appear, as the values of $a$ and $b$ are given by the input, and the input can be set such that a-b is positive.
Output
The output file camp.out contains a CAM program consisting only of the instructions described above. Your output format must satisfy:
At most one instruction per line.
All instruction identifiers (LOOP, END, L, R) must be uppercase.
In LOOP and END instructions, there must be at least one space between every two symbols in the symbol table, and at least one space between the first symbol of the table and the instruction identifier. The symbol table does not need to be in any specific order. The same symbol can be repeated, but repeated symbols are only counted once.
Spaces or tabs can be placed anywhere in the program, but these delimiters cannot split an instruction identifier.
Use # to indicate a line comment. If there is an instruction before #, there must be at least one space between the instruction and #.
The output program cannot exceed $100,000$ lines.
Examples
Input 1
a+1
Output 1
LOOP 0 1 R ? END ? L ? LOOP 1 L 0 END ? L 1
Note
The example above is the same as the one described in the problem. The comments have been removed (you may add them, as they do not affect correctness), and the final pointer movement to the start of the integer has been omitted. This does not affect the result.
Scoring Criteria
The problem consists of 10 test cases, each worth 10% of the total score. For each output, we will design one or more input strings for the tape. Each input string has a certain point value. If your program finishes within 100,000 steps (inclusive) under the given input and leaves the correct result on the tape, you will receive the corresponding points.
Constraints
| Input ID | Number of Operators | Possible Operators | Parentheses Possible |
|---|---|---|---|
| 1 | 1 | $+,-$ | No |
| 2 | 1 | $+,-$ | No |
| 3 | 1 | $+,-$ | No |
| 4 | $\le 2$ | $+,-$ | No |
| 5 | $\le 3$ | $+,-$ | Yes |
| 6 | $\le 3$ | $+,-$ | Yes |
| 7 | 1 | $+,-,*$ | No |
| 8 | $\le 2$ | $+,-,*$ | No |
| 9 | $\le 3$ | $+,-,*$ | Yes |
| 10 | $\le 3$ | $+,-,*$ | Yes |