This is not an interactive problem.
What is the favorite game of programmers? Without a doubt, it's competitive programming! It offers an endless array of challenges that span all conceivable varieties. It's a boundless arena filled with problems featuring ingenious concepts, intricate implementations, unexpected discoveries, and elaborate edge cases. Moreover, there are numerous unique and original problems to solve. Speaking of originality, have you ever encountered interactive problems? They represent the pinnacle of creativity in the problem-solving landscape.
In a typical problem, a solution reads input data and produces output. However, in an interactive problem, the contestant's program must communicate with the jury's program first, and then the interactor will produce output that the checker will verify.
You might wonder how much more difficult it is to check these interactive problems. Alongside a checker, there is an interactor that validates the solution and can detect errors. During this communication, new avenues for errors may arise: the participant's program might crash unexpectedly, become unresponsive, or encounter other issues. Every conceivable scenario must be covered within the rules, and clarity is crucial to ensure a fair and enjoyable competition, especially for newcomers.
Simply adding an interactive problem to a regular contest without adjusting rules, testing libraries, or the testing system is a very bad idea. Imagine receiving the same verdict for a protocol violation, exceeding query limits, or an unexpected program termination. Or finding yourself in a situation where you completely forgot to output the answer, but get a "Wrong Answer" verdict (or facing "WA" on a problem that doesn't have anything that looks like an answer). Even worse would be having official rules that allow for random verdicts.
So, what if someone, perhaps I, decided to organize a contest featuring interactive problems? We cherish our participants and strive to provide them with the best experience. Thus, we need to create a solid foundation to support interactive problems. Are you wondering why I'm telling you all this? Not sure?... Yes, you are correct! You will be the one tasked with building a tool that will help test interactive problems!
Creating a comprehensive library that supports any kind of interactive problem is a lengthy project, and time is of the essence. For now, let's support a very limited number of problems --- enough to grasp the concept and allow for independent development in the future.
Let's start with the basics. The main feature is the communication between the participant's program and the interactor. The interactor reads data from the participant's output, processes it, and sends a response, then fetches another chunk of data, processes it, responds once more, and so on. However, program output is treated as an infinite stream. How will the interactor know when to stop reading and start processing data? When does a participant's program begin to wait for a response? If we examine the communication log for a specific problem, we humans can see where one query ends and another one begins. So, let's establish formal rules to do that automatically.
Remember, we are only considering a few possible types of problems. In every problem we consider, only the participant's program issues queries, and the values in the queries may only be integers. For every query, there is one pattern assigned. The pattern consists of words, integer placeholders, spaces, and newline characters. If the participant's output completely matches the pattern, we may assume that the interactor has read the next query. Here are some conditions for patterns:
%d" and must be adjacent only to spaces or newline characters.However, this definition is still insufficient. Let's define a term called the stop symbol of the pattern that will satisfy the following conditions:
Let the interactor have a buffer to read the user's output. The interactor reads user data byte by byte and stores it in a buffer. The algorithm for reading queries is outlined as follows:
Now that we've finished discussing reading queries, let's consider the issues that may arise during this process. There are two types of issues: those where no pattern is read, and those where reading is successful but processing is incorrect.
In the first case, if the interactor fails to read a query, it signals an issue with the participant's program: it may have crashed, exceeded a limit, or just terminated unexpectedly. The possible verdicts are as follows:
Time-limit exceeded". The participant's output of the last exchange is incomplete and has exceeded the allowable time limit.Memory limit exceeded". The participant's output of the last exchange is incomplete and has exceeded the memory constraints.Runtime error". The participant's output of the last exchange is incomplete and encountered a failure.Unexpected termination". The participant's output of the last exchange is incomplete, yet the program terminated without error.If the interactor successfully reads the pattern but fails to process it, the possible verdicts are:
Exchange limit exceeded". The participant's output of the last exchange is valid, but right after that, the exchange limit described in the statement is exceeded. This verdict is typically issued when there is excessive communication between the participant's and jury's programs, indicating an overflow of queries or insufficient progress toward finding a solution within the required number of actions.Protocol violation". The participant's output of the last exchange is either valid but does not pass validation checks, or it is invalid.Incorrect solution". The participant's output of the last exchange is valid but violates constraints defined in the problem statement; it is akin to a Wrong Answer but flagged specifically by the interactor.Once communication is complete, the interactor writes the answer and transfers it to the checker. If the program does not terminate after writing the last query and fails, the corresponding verdict ("ML", "TL", "RE") must be evaluated. If excess data is written, a protocol violation will be reported immediately. The possible verdicts of the checker are:
OK". The solution is considered correct.Wrong answer". The checker reports that the provided answer is incorrect.Now that we have the common details of the library established, I hope you understand them well! Let's delve into the problems you need to support.
As previously mentioned, each problem defines one or more patterns for queries, with the last pattern corresponding to the terminal query. The problem may have the following four features:
Protocol violation" should be raised.Incorrect solution" will be rendered.The first few lines will describe the features of the problem. Each line will contain "Yes" if the feature is enabled and "No" otherwise.
Following this information, there will be a single integer $n$ ($2 \leq n \leq 10$) indicating the number of patterns. The next $n$ lines will describe the patterns, one per line. In a pattern, the newline character is specified by "\n". Square brackets indicate stop symbols. Square brackets cannot overlap. The length of each pattern does not exceed $50$ characters.
After the pattern definitions, the outputs from the participant's program will be provided. Each output is terminated by the delimiter "###" followed by a newline character. If the participant's solution does not exit successfully, the output (before the delimiter) will end with one of the strings "*TL*", "*ML*", or "*RE*", each followed by a newline character. These mean, respectively, that the program worked too long, consumed too much memory, or just crashed, and must be processed accordingly.
The numbers in the participant's output will be decimal integers from $0$ to $1\,000\,000$ without leading zeroes. Each line of a participant's output is at most $50$ characters long. A digit will not be immediately preceded by a dash.
The total size of the input does not exceed $200$ kilobytes.
For each output from the participant's program, provide the resulting verdict on its own line.