eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Processor`s game

Processor`s game

Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB

Vasya Pupkin’ coursework on electronics is to create a simple microprocessor. According to the statement this microprocessor has only three registers: the accumulator, the instruction pointer and stack pointer. The accumulator has 60 bits, the instruction and stack pointers has 7 bits. The accumulator can store positive and negative numbers (in binary complement code: Binary complement code of negative number is equal to difference between 260 and absolute value of that negative number. For example, -5 in decimal complement code could be written as 1152921504606846971, and in binary com-plement code as 111111111111111111111111111111111111111111111111111111111011).

The processor can execute the following commands (ACC – the accumulator, IP – instruction pointer, SP – stack pointer, [X] – element of the stack with the address X):

The program is located in cells with addresses from 0 to 127. Each memory cell can contain exactly one command (including the constant value, if it exists). Be-fore beginning execution, the accumulator is set to the value to be processed, and reg-isters IP and SP are zeroed. The result of calculation is the value of the accumulator after the program stops.

Given microprocessor program, write a program that calculates its result for each provided accumulator value.

Вхідні дані

The first line contains two integers n and m, separated by spaces, where n – number of commands in the program, m – number of values of accumulator for which you should make calculations. The subsequent n lines contain the commands in the following format:

"Address of memory cells," "space" "command’s mnemonic" ["space", "argument."]

Command are listed sequentially from cell with address 0 to cell with address n-1.

The program is followed by m integers a_i – initial values of the accumulator, which should be processed by microprocessor. The numbers are separated by spaces.

1n128; 1m10^3, –2^59a_i < 2^59.

All mnemonics are written with capital Latin letters, and a constant X is specified as a decimal number (possibly signed) ranged from –2^59X < 2^59; for the CALL command 0X127.

The given program has a finite run time, and never overflows the stack.

Вихідні дані

The first line of the output file should contain integer m – the number of calculated values. Following m lines should contain the results of calculations for input values a_i, placed in the same order as a_i,, one per line.

Приклад

Вхідні дані #1
6 2
0 ADD 9
1 CALL 4
2 SUB 3
3 RET
4 NEG
5 RET
1 10
Вихідні дані #1
2
13
22