Guido van Rossum Built Python Out of Christmas Boredom

No attempts yetTime limit1sMemory limit128 MB

Problem

Guido van Rossum is said to have created Python because he was bored on Christmas. So you, being bored too, built yourself a computer.

This computer consists of a single processor that uses only a very small set of instructions, 32 bytes of memory, an 8-bit accumulator, and a 5-bit program counter (PC). It follows the von Neumann architecture, so program and data share the same memory.

The program counter holds the address of the next instruction to execute. Each instruction is 1 byte long: the upper 3 bits give the instruction type and the lower 5 bits give the operand. The operand is always a memory address (xxxxx). Some instructions need no operand, in which case the lower 5 bits are meaningless (-----). The instructions are:

000xxxxx STA x Store the accumulator's value into memory address x.
001xxxxx LDA x Load the value at memory address x into the accumulator.
010xxxxx BEQ x If the accumulator is 0, set the PC to x.
011----- NOP Do nothing.
100----- DEC Decrease the accumulator by 1.
101----- INC Increase the accumulator by 1.
110xxxxx JMP x Set the PC to x.
111----- HLT Halt the program.

Initially both the PC and the accumulator are 0. After an instruction is fetched and decoded, the PC is increased by 1 before that instruction is executed. You may assume the program always terminates.

Input

The input consists of several test cases. Each test case is given over 32 lines; each line is one byte of memory (that is, the code), listed from address 0 in order, written as an 8-bit binary number. The leftmost bit is the most significant. The input ends at end of file (EOF).

Output

For each test case, print on one line the accumulator's value when the program terminates, as an 8-bit binary number. Here too, the leftmost printed bit is the most significant.

Hint

The accumulator is 8 bits, so whenever its value goes out of range only the lower 8 bits are kept. For example, performing INC when the accumulator is 11111111 yields 00000000. The program counter is likewise 5 bits, so by the same rule, when its value reaches 32 only the lower 5 bits remain and it becomes 0.