A small computer has 10 registers and 1000 words of RAM. Each register and each RAM word stores a 3-digit integer from 0 to 999. Instructions are encoded as 3-digit integers and are stored in RAM. Every register starts at 000, and the initial RAM contents are given on standard input. Execution begins with the instruction at RAM address 0. Every arithmetic result is reduced modulo 1000.
The instruction encodings are:
Here d, s, and a are single digits (0-9) naming a register, and n is a single digit (0-9).
The input consists of up to 1000 three-digit unsigned integers, one per line, giving the contents of consecutive RAM words starting at address 0. Any RAM word not listed is initialized to 000.
Print a single integer: the number of instructions executed, counting up to and including the halt instruction. The program is guaranteed to halt, in at most 100000 instructions.