P4911 Kappa Heavy Industries’ Computer.

Background

The computer products of Kappa Heavy Industries are widely used throughout Gensokyo. One day, Youkai Mountain was flooded. The flood, mixed with mud and rolling logs, surged into the kappa city. The kappa’s mechanical facilities were originally waterproof, but the flood still caused serious damage to the city. Among them, the kappa’s servers were smashed! The broken computers cannot be repaired in a short time, but many things in Gensokyo cannot work without the kappa’s servers. The kappa had no choice, so Nitori came to you. As an excellent competitive programming contestant, you decide to help Nitori and reduce the pressure caused by the server failure.

Description

You received a paper document from Nitori, and the scanned version is here: [Ktx-65式微处理器汇编语言规范文件.pdf](https://www.touhou-oi.tk/uploads/Ktx-65%E5%BC%8F%E5%BE%AE%E5%A4%84%E7%90%86%E5%99%A8%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80%E8%A7%84%E8%8C%83%E6%96%87%E4%BB%B6.pdf) (If this website cannot be opened, please download it from the attachments.) (Why is it called a scanned version? Because you probably cannot copy the text inside.) The following part is an example included with the assembly tutorial: ```asm [ progfunc.asm ] [ Shows the function functionailties of the KTX-65 ALI ] [main] wint #line; [output the current physical line number] wch 13; [putchar \r] wch 10; [putchar \n] callfunc $Function1; callfunc $Function2; hlt; [halt] function $Function1; rint %r1; [read int] add %r2 1 %r2; [loop contents] lle %r2 %r1; [loop conditions] jif 2; [end loop conditional jump] wint %r2; [output int] wch 13; [putchar \r] wch 10; [putchar \n] ret; [return] function $Function2; rint %r1; [read int] rint %r2; [read int] add %r1, %r2; [add] wint %val; [output value] wch 13; [putchar \r] wch 10; [putchar \n] ret; [return] ``` You need to write a program in a language supported by the Luogu judge. It reads a Ktx-65 assembly program and an input stream, interprets and runs the program, and then outputs what the program outputs.

Input Format

The first line is an integer $N$, meaning the number of lines of the assembly program. The next $N$ lines are the assembly program, and it is guaranteed that there are no empty lines. All remaining lines are the input for this assembly program.

Output Format

A bunch of stuff, representing the output of this assembly program. **~~The judge will compare your output byte by byte to determine correctness~~**. This is fake; Luogu does not support it.

Explanation/Hint

**Note**: In the sample output, there is only the single byte $9$. **It is guaranteed that each line contains only one instruction.** For $10\%$ of the testdata: the program contains only input and output instructions, and there will be no numeric constants and no comments. For another $10\%$: the program contains only input, output, and addition instructions, and there are no comments. For another $30\%$: all instructions are included except function calls and jumps. For the remaining $50\%$: there are no restrictions on instructions. For all testdata: the number of commands does not exceed $50000$, the remaining input does not exceed $500$ kilobytes, and the number of steps the program needs to execute does not exceed $80000$ steps. It is guaranteed that the assembly program and the input data will not have compilation or runtime errors. It is guaranteed that the program input is sufficient for what the assembly program needs to read. It is not guaranteed whether this is or is not a nasty problem. It is not guaranteed whether anyone will AC this problem during the contest. It is not guaranteed whether anyone will AK in this contest. It is guaranteed that the problem setter is: [洩矢诹访子](https://www.luogu.org/space/show?uid=53151) If you cannot open the file given by the kappa during the contest, you can ask me for it. It is not guaranteed whether I will respond. ~~Actually, the testdata for this problem is very simple, it is just large in size.~~ Translated by ChatGPT 5