Nils has developed a new programming language, Nils++!
A Nils++ program consists of multiple lines. Each line is either blank (in which case it will be ignored), or contains exactly one statement. Due to computing limitations, there cannot be more than statements.
A Nils++ interpreter uses cells, labelled from to . Each cell contains an integer, which must be in the range at all times.
There are only six different types of statements:
ADD A B C
Compute the sum of the values in cells A and B, and store the result in cell C.NEG A B
Negate the value in cell A, and store the result in cell B.ABS A B
Calculate the absolute value of the value in cell A, and store the result in cell B.SGN A B
Calculate the sign function of the value in cell A, and store the result in cell B.CLR A B
If the value in cell A is nonzero, set the value in cell B to . Otherwise, if the value in cell A is , then do nothing.OUT A
Output the value in cell A.
Note that A
, B
and C
represent integers between and (inclusive).
The output of the program is the sequence of values outputted using the OUT
statement, in the order that they were outputted.
In order to demonstrate the versatility of his programming language, Nils wishes to create various Nils++ programs that solve different tasks. The seven tasks are listed below:
Task 1: EQUALS
- Initially, cell 1 contains an integer , and cell 2 contains an integer . All other cells contain the integer .
- .
- At least one of and is nonzero.
- You should output a single integer, equal to if , and if .
Task 2: MAX
- Initially, cell 1 contains an integer , and cell 2 contains an integer . All other cells contain the integer .
- .
- You should output a single integer, equal to .
Task 3: PRODUCT
- Initially, cell 1 contains an integer , and cell 2 contains an integer . All other cells contain the integer .
- .
- You should output a single integer, equal to .
Task 4: GCD
- Initially, cell 1 contains an integer , and cell 2 contains an integer . All other cells contain the integer .
- .
- You should output a single integer, equal to .
Task 5: XOR
- Initially, cell 1 contains an integer , and cell 2 contains an integer . All other cells contain the integer .
- .
- You should output a single integer, equal to . Here, denotes the bitwise XOR operator.
Task 6: PRIMES
- Initially, cell 1 contains an integer . All other cells contain the integer .
- .
- You should output a single integer, equal to number of primes which are less than or equal to .
Task 7: SORT
- Initially, cells to contain the integers respectively. All other cells contain the integer .
- .
- You should output integers. The output of the program should be the result when is sorted.
Experimentation
You will be provided with a Nils++ interpreter for local testing purposes. There are two versions of the interpreter, one written in Python and one written in C++.
Both of the interpreters read from standard input and write to standard output.
The first line of input should contain a single integer, , satisfying . This represents that the first cells will be initialised to specified values, with all other cells being initialised to .
The second line should contain space-separated integers, with each integer in the range . These represent the initial values contained in cells respectively.
The remaining lines of input should contain the Nils++ program.
Both interpreters will print out all values outputted using the OUT
statement, in the order they were outputted, with one integer on each line.
Note that the interpreters are intended solely for testing purposes, and as such may not parse poorly-formatted input properly.
Subtasks
Subtask | Points | Task | Additional Constraints |
---|---|---|---|
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- |
Input Specification
The only line contains a single integer between and (inclusive), representing the task number.
Output Specification
Output one or more lines. Each line should be blank, or contain exactly one statement in the described format. There should be at most non-empty lines.
Sample Input
1
Sample Output
ADD 1 2 1
NEG 2 3
SGN 3 3
ABS 3 3
CLR 1 3
OUT 3
Explanation
This program is supposed to output whether two numbers are equal. This sample output would not be accepted, and is intended only as a clarification of the behaviour of each statement.
Let's assume that initially, cell contains the integer , cell contains the integer , and all other cells contain the integer . Denote as the integer stored in cell . Then, the interpreter would execute the following:
- Calculate . Then, set to .
- Calculate . Then, set to .
- Calculate . Then, set to .
- Calculate . Then, set to .
- Since is nonzero, set to .
- Output .
The actual output of the program is , but the correct output is since cells and initially contained the same integer. Hence, this program would receive a Wrong Answer
verdict.
Comments