zmaj | 프로그래밍의 벗 PivotOJ
PivotOJ

zmaj

시간 제한: 2000ms메모리 제한: 128MB출처: CHC 2005 Final Exam #1BOJ 3203

문제

Programming language ZMAJ (somewhat similar to BASIC) has 26 variables denoted by lowercase letters of the English alphabet ('a'-'z'). Initial value of all the variables is 0, and during program execution they can store integer values between 0 and 9999 (inclusive). Result of any operation in the program is reduced modulo 10,000 before it is stored into a variable. 

Each line of our program contains exactly one of the following commands: 

BEGIN appears only at the beginning of the program.
= to the variable on the left side of the operator we assign the value of the expression on the right side. Expression consists of one or more addiction and subtraction operations on terms, where each term is either a constant or a variable possibly multiplied by a constant (i.e. a = 2b + 4 - c). Each binary operator will be surrounded by one space character on each side, and unary minus operator is not allowed. Constants are integers between 0 and 999 (inclusive).
REPEAT n denotes the beginning of the block that is repeated n times, 1 ≤ n ≤ 100,000.
STOP denotes the end of the REPEAT block or end of program.
PRINT var prints the current value of variable var in the following format 'var = value'.

Write a program that will generate output for the given ZMAJ program. 

입력

Input will contain a legal program in the programming language ZMAJ, and it will be at most 50 lines long. 

Each line of input contains one command and each command will have at most 100 characters. 

Blocks of command inside BEGIN...STOP or REPEAT...STOP will be indented exactly 3 spaces. 

출력

Output should contain all the outputs from PRINT commands during the program execution. 

Note: input will be such that the PRINT command will execute at most 20 times. 

예제

예제 1

입력
BEGIN
   n = 10
   k = 1
   REPEAT 3
      REPEAT 2
         n = n + k
         PRINT n
      STOP
      k = 3 - k
   STOP
STOP
출력
n = 11
n = 12
n = 14
n = 16
n = 17
n = 18

예제 2

입력
BEGIN
   a = 1
   b = a
   PRINT a
   PRINT b
   REPEAT 10
      c = a + b
      a = b
      b = c
      PRINT c
   STOP
STOP
출력
a = 1
b = 1
c = 2
c = 3
c = 5
c = 8
c = 13
c = 21
c = 34
c = 55
c = 89
c = 144

예제 3

입력
BEGIN
   x = 1
   REPEAT 4
      REPEAT 99999
         x = 2x
      STOP
      PRINT x
   STOP
STOP
출력
x = 4688
x = 7344
x = 8672
x = 4336
코드를 제출하려면 로그인하세요.