Bit Shift Registers
문제
Christopher the engineer is working on a new type of computer processor.
The processor has access to different -bit memory cells (where and ), which are called registers, and are numbered from to . We denote the registers by , , , . Each register is an array of bits, numbered from (the rightmost bit) to (the leftmost bit). For each () and each (), we denote the -th bit of register by .
For any sequence of bits , , , (of arbitrary length ), the integer value of the sequence is equal to . We say that the integer value stored in a register is the integer value of the sequence of its bits, i.e., it is .
The processor has types of instructions that can be used to modify the bits in the registers. Each instruction operates on one or more registers and stores the output in one of the registers. In the following, we use to denote an operation of changing the value of such that it becomes equal to . The operations performed by each type of instruction are described below.
- : Copy the array of bits in register to register . For each (), set .
- : Set register to be equal to , where is an array of bits. For each (), set .
- : Take the bitwise-AND of registers and , and store the result in register . For each (), set if both and are , and set otherwise.
- : Take the bitwise-OR of registers and , and store the result in register . For each (), set if at least one of and are , and set otherwise.
- : Take the bitwise-XOR of registers and , and store the result in register . For each (), set if exactly one of and is , and set otherwise.
- : Take the bitwise-NOT of register , and store the result in register . For each (), set .
- : Shift all bits in register to the left by , and store the result in register . The result of shifting the bits in register to the left by is an array consisting of bits. For each (), if , and otherwise. For each (), set .
- : Shift all bits in register to the right by , and store the result in register . The result of shifting the bits in register to the right by is an array consisting of bits. For each (), if , and otherwise. For each (), set .
- : Add the integer values stored in register and register , and store the result in register . The addition is carried out modulo . Formally, let be the integer value stored in register , and be the integer value stored in register before the operation. Let be the integer value stored in register after the operation. If , set the bits of , such that . Otherwise, set the bits of , such that .
Christopher would like you to solve two types of tasks using the new processor. The type of a task is denoted by an integer . For both types of tasks, you need to produce a program, that is a sequence of instructions defined above.
The input to the program consists of integers , , , , each having bits, i.e., (). Before the program is executed, all of the input numbers are stored sequentially in register , such that for each () the integer value of the sequence of bits , , , is equal to . Note that . All other bits in register (i.e., those with indices between and , inclusive) and all bits in all other registers are initialized to .
Running a program consists in executing its instructions in order. After the last instruction is executed, the output of the program is computed based on the final value of bits in register . Specifically, the output is a sequence of integers , , , , where for each (), is the integer value of a sequence consisting of bits to of register . Note that after running the program the remaining bits of register (with indices at least ) and all bits of all other registers can be arbitrary.
- The first task () is to find the smallest integer among the input integers , , , . Specifically, must be the minimum of , , , . The values of , , , can be arbitrary.
- The second task () is to sort the input integers , , , in nondecreasing order. Specifically, for each (), should be equal to the -th smallest integer among , , , (i.e., is the smallest integer among the input integers).
Provide Christopher with programs, consisting of at most instructions each, that can solve these tasks.