eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач

Gnirut

Some interesting documents have recently been found in the ACM archives. These documents contain an account of the original version of the ACM ICPC competition, which took place in Bletchley Park, England, in the year \textbf{1943}. In this original contest, programs submitted by contestants were executed in a simpli ed version of the so-called deterministic Turing Machine, which undoubtedly most of you are familiar with. In this simpli ed version, the tape is not in nitely long. Instead, tape cells are numbered \textbf{0} to \textbf{10^3-1} (inclusive), from left to right. Also, the alphabet used is the unary alphabet, meaning that, prior to the execution of the program, the tape will be initialized with the string consisting of \textbf{n} ones followed by all zeroes, where \textbf{n} is the numerical value of the input, and after execution the tape contents should be \textbf{m} ones followed by all zeroes, where \textbf{m} is the numerical value of the corresponding output. In the beginning, the tape head is at position \textbf{0}, and states are also numbered starting with \textbf{0}, which is assumed to be the initial state. The machines work as usual: for every machine state \textbf{q} and every bit \textbf{c} (\textbf{0} or \textbf{1}), there is a at most one rule determining what the next state will be if the symbol at the position of the tape head is \textbf{c} and the current state is \textbf{q}; the rule also speci es the symbol to write at the current position and in which direction the head should move. When no rule applies, the machine stops. Unfortunately, only the verdicts of the contest judge were found in the archives, there being no trace of the Turing machines submitted or the test cases used. Note that in this original contest, unlike the current one, there was a different verdict for each test case, instead of a general one. This discovery has caught the attention of the famous adventurer Zaphod Beeblebrox, who intends to launch a project to construct examples of machines and input/output "\textbf{files}" that might have caused these verdicts. Not only have all your e orts to make him understand the futility of such an enterprise failed miserably, but you also have been coerced into writing a program for him that generates such examples. Your program should receive a series of verdicts about one of the Turing machines submitted by the contestants, and return the speci cations of a Turing machine, as well as a series of test cases, for which the verdicts are the ones you received. We consider the output for a machine should be \textbf{MLE} (memory limit exceeded) if the machine attempts to access any cell outside the tape range speci ed above; \textbf{TLE} (time limit exceeded) if it runs for at least \textbf{10^4} iterations without stopping or causing a \textbf{MLE} error; \textbf{WA} (wrong answer) if the machine stops but returns an incorrect result, and \textbf{AC }(accepted) if the machine stops and returns the expected result. \InputFile The input consists of a certain number (no larger than \textbf{30}) of series of verdicts. The first line for each contains \textbf{1} ≤\textbf{N }≤ \textbf{100}, the number of verdicts in the case. The following \textbf{N} lines contain one of the words \textbf{TLE}, \textbf{MLE}, \textbf{WA} and \textbf{AC}. The end of input is signaled by a case with \textbf{N = 0}, which should not be processed. \OutputFile For a given test case for your program, your output should adhere to the following format: The first line contains \textbf{1} ≤ \textbf{M} ≤ \textbf{1000}, the number of rules for the machine, and \textbf{N}, the number of test cases for the Turing Machine. \textbf{M} lines follow, each one containing a rule, in the format \textbf{q_prev c_prev q_next c_next mov}. \textbf{q_prev} is the state of the machine before the rule is applied, \textbf{c_prev} is the content (either \textbf{0} or \textbf{1}) of the tape at the current position \textbf{p} before the rule is applied, \textbf{q_next} is the state of the machine after the rule is applied, \textbf{c_next} is the content of position \textbf{p} after the rule is applied, and \textbf{mov} is the direction in which the tape head moves one step after applying the rule ("\textbf{L}" if it moves to the left and "\textbf{R}" if it moves to the right). The states should be integers between \textbf{0} and \textbf{1000}, inclusive. The Turing machine should be deterministic, that is, there should be at most one transition from any pair (\textbf{q_prev}, \textbf{c_prev}), and should not be repeated in your output. After this, \textbf{N} lines follow, each one containing two space-separated numbers, \textbf{X} and \textbf{Y}, \textbf{1} ≤ \textbf{X}, \textbf{Y} ≤ \textbf{1000}. \textbf{X} is the value of the input to the program, and \textbf{Y} is the value of the expected output. \textit{\textbf{Note}}: While this is the recommended syntax, other combinations of new lines and whitespace characters might also get accepted.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
1
AC
0
Выходные данные #1
2 1
0 1 0 1 R
0 0 2 1 R
4 5