| 2024 China Collegiate Programming Contest (CCPC) Jinan Site (The 3rd Universal Cup. Stage 17: Jinan) |
|---|
| Finished |
Note: This is the inverse version of problem "The Emperor" with differences in constraints.
Capoo invented an interesting language named Push-Pop. This language is an interpreted language. The interpreter starts with an empty stack with infinite capacity and reads the first instruction of the custom program. There are only two kinds of instructions in this language:
If the top element of the stack is $$$a$$$, then pop the stack once and transfer the control flow to the $$$x$$$-th instruction (which means the next instruction will be the $$$x$$$-th). Otherwise, push an element $$$b$$$ into the stack and transfer the control flow to the $$$y$$$-th instruction.
If the stack is empty, halt the whole program after executing this instruction. Otherwise, push an element $$$b$$$ into the stack and transfer the control flow to the $$$y$$$-th instruction.
Capoo wants to construct a Push-Pop program that halts after executing exactly $$$k$$$ instructions. Due to the naive implementation of the interpreter, a program can contain at most $$$64$$$ instructions.
The only line contains a single integer $$$k$$$ ($$$1\le k \le 2^{31} - 1$$$, $$$k$$$ is odd).
The first line contains an integer $$$n ~(1\le n\le 64)$$$ denoting the number of instructions, and then follows $$$n$$$ lines denoting the Push-Pop program. For each instruction, $$$1\le a,b\le 128,~ 1\le x,y\le n$$$ should hold.
It is guaranteed that a solution exists for given input.
1
1 HALT; PUSH 1 GOTO 1
5
5 POP 1 GOTO 2; PUSH 1 GOTO 2 HALT; PUSH 1 GOTO 3 POP 1 GOTO 4; PUSH 2 GOTO 4 POP 1 GOTO 2; PUSH 2 GOTO 4 HALT; PUSH 99 GOTO 4
For the second example, instructions are: 1(PUSH), 2(PUSH), 3(POP), 4(POP), 2(HALT).
Key differences in constraints comparing to "The Emperor":
| Name |
|---|


