시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB432100.000%

## 문제

You have found a weird box in your grandma’s basement. A careful inspection revealed that it is an old-school computer. You tried to run some simple programs but they all behaved very weirdly. It took you some time before you were able to pinpoint the reason: the computer uses ternary logic and arithmetic!

trit is the ternary equivalent of a bit. Our trits can store the values 0, 1, 2. When doing logical operations with trits we imagine that 0 represents false, 1 represents unknown, and 2 represents true.

The computer has 26 registers, labeled A through Z. Each register is a 40-trit unsigned integer variable.

At the beginning of your program’s execution, the register X contains the input number and all other registers contain zeros. It is guaranteed that X is between 0 and 109, inclusive.

Write a program that will set Y to 1 if X is prime, and leave it at 0 if it isn’t. (Recall that the numbers 0 and 1 are not prime.)

Your program must contain at most 5,000 commands.

## Operators

The computer supports the standard arithmetic operators: +-*/ (integer division), and % (modulo). All computations are done modulo 340. Division and modulo by zero cause a runtime error.

The computer also supports the following tritwise operators:

• & (and) returns false if either operand is false, true if both are true, and unknown otherwise
• | (or) returns true if either operand is true, false if both are false, and unknown otherwise
• ^ (xor) is addition (without carry) modulo 3
• ~ (unary not) is subtraction from 2
• << (shift left) and >> (shift right) behave as expected, new trits are set to 0

• 2103 & 1113 = 1103
• 2103 | 1113 = 2113
• 2103 ^ 1113 = 0213
• ~ 2103 = 222…2220123 (i.e., 37 twos followed by 012)
• 2103 << 2 = 210003
• 2103 >> 2 = 23.

## Programs

You suspect that there are some instructions for loops and jumps and such, but so far you weren’t able to discover any. Thus, in this problem you will have to do without such fancy tools. A program is therefore a finite sequence of commands. Each command will be executed exactly once, in the given order. Each command has one of three forms:

• [register] = [operand]
• [register] = [operand] [operator-with-two-operands] [operand]
• [register] = [operator-with-one-operand] [operand]

Here, operators are the ones listed above and each [operand] is either a register or an integer constant that fits into a register.

Constants can be given either in base-10 or in base-3. Base-10 constants have no prefix, base-3 constants have a prefix “0t” (zero, lowercase t). For example, 47 and 0t001202 represent the same number.

At least one space between each two tokens is mandatory.

## 입력

There is no input.

## 출력

Your output file must contain a program that meets the above specifications and solves the given subproblem.

Note that empty lines and extra whitespace on each line are ignored, feel free to use those to format your program for better human readability. Only non-empty lines are counted towards the limit on the number of instructions. Remember that at there must be at least one space between any two tokens in your program, and at least one newline between any two commands.

## Example

At the beginning of our program’s execution, the register X contains the input number and all other registers contain zeros. We want to find the last non-zero digit of X (if any) and set it to zero.

One possible program that does this looks as follows:

## 예제 출력 1

A = X - 1
B = ~ A
C = B ^ X
X = X & C


## Testing

A very basic interpreter is provided on a best effort basis on an external site. The interpreter will start in a state with zeros in all registers, execute up to 5000 commands of the program you provide, and report either an error that occurred, or the number of commands executed and final values in all registers.

Text

## 채점 및 기타 정보

• 예제는 채점하지 않는다.