time limit per test: 0.5 sec. memory limit per test: 65536 KB
input: standard output: standard
The new IMB compiler "Unvisual Age for PL/Cool" is planned for release next month. Your task in this problem is to write the interpreter for the PL/Cool language so that the compiler programmers could test their product.
Program on PL/Cool can contain expressions. Each expression can contain integer constants and variables. The following operations are allowed: + (add), - (substract), * (multiply), / (divide), % (modulo), and ^ (raise). ll operations have their usual meaning and priority (^) > (*) = (/) = (%) > (+) = (-), all operations except ^ are evaluated from left to right, ^ is evaluated from right to left. Parenthesis can be used to change the order of evaluation, as usually. Unary minus and plus are allowed, their priority in this case is the highest.
Divide operation acts like integer division: first both operands are replaced with their absolute values, next integer division is performed, remainder is dropped, and finally the sign of the quotient is set equal to the sign of the true quotient of the operands. Taking modulo is perfomed the same way, except that the quotient is dropped and remainder is kept. For example, (80+4*75)/(56-2^2^3) = -1.
Program may contain variables. Variable name starts with a letter, which may be followed by letters and digits. Variable names are case insensitive. Maximal name length is 10 characters.
PL/Cool has two operators: "print" and "define". Program is the sequence of the operators, one on a line.
Operator "print" has the following syntax:
Here <expression> is any expression that may contain variables and integer constants. Operator "print" prints the value of the expression.
Operator "define" has the following syntax:
define <operand1> <operand2>
Here <operand1> and <operand2> are either variables or non-negative integer constants. After execution of the "define" operator, all occurences of the <operand1> are replaced with the <operand2>. Define operator can be used even to change the value of the integer constants, for example after
define 2 4
the value of 2+2 is 8.
Note that substitution is performed recursively, until some undefined constant is met, for example the following sequence of operators prints 8 and 10:
An attempt to redefine some variable or constant is ignored. An attempt to make a definition that leads to circular dependence is also ignored. For example, the following sequence prints 4 and 4, because the last two definitions are ignored.
If some identifier is used in the expression that is not yet defined to be substituted by some integer constant, its value is set to zero. For example, the following operator prints 3:
print x + 3
Input file contains the program on PL/Cool. All numbers in the expressions, including numbers that occur during expression evaluation, do not exceed 109 by their absolute value. The total number of "define" operators does not exceed 30000, the total number of "print" operators does not exceed 2000, the length of each line does not exceed 200 characters.
In case of division denominator is never zero, zero is not raised to zero power and power exponent is always non-negative.
Output file must contain the output of all print operators in the order they are executed, one on a line.