Phigon
The programming language "Phigon" has recently gained popularity due to its concise and compact syntax. However, programs written in "Phigon" can be challenging to understand, particularly when it comes to determining why they may take a long time to execute.
Your task is to develop a program analyzer to count the number of operations performed in a "Phigon" program. We will use a simplified model of a "Phigon" program for this purpose. Examples of "Phigon" programs are provided at the end of this description. Like any programming language, "Phigon" includes variables. Variable names are strings of lowercase Latin letters, with a maximum length of 50. The names "if", "while", "or", "and", and "not" are reserved and cannot be used as variable names.
"Phigon" supports arithmetic expressions that consist of integers, variables, and the arithmetic operators "+", "-", and "*". Formally, arithmetic expressions in "Phigon" are defined as follows:
<arithmetic expression> ::= <term> | (+|-) <arithmetic expression>
<term> ::= <factor> | <factor> * <term>
<factor> ::= -<factor> | <non-negative number> | <variable> | (<arithmetic expression>)
In "Phigon", the unary minus has a higher precedence than multiplication, which in turn has a higher precedence than addition. Each negative number in the program is treated as the result of applying the unary minus to a positive number. For instance, the negative number -42 is interpreted as applying the unary minus to the positive number 42.
"Phigon" also includes assignment operators, which are structured as follows:
<assignment operator> ::=
<variable> = <arithmetic expression>
Executing an assignment operator assigns the value of the arithmetic expression on the right to the variable on the left. Once a variable is assigned a value, it is considered declared and can be used in subsequent arithmetic expressions.
Logical expressions in "Phigon" are composed of arithmetic expressions, comparison operators "<", "<=", ">", ">=", "==", "!=", and logical operators "and", "or", and "not". Formally,
<logical expression> ::= <conjunction> | <conjunction> or <logical expression>
<conjunction> ::= <logical condition> | <logical condition> and <conjunction>
<logical condition> ::= not <logical condition> | <arithmetic expression>
(<|<=|>|>=|==|!=) <arithmetic expression> | (<logical expression>).
In "Phigon", negation has a higher precedence than the conjunction operator "and", which in turn has a higher precedence than the disjunction operator "or".
The conditional operator in "Phigon" is structured as follows:
<conditional operator> ::=
if <logical expression>:
<indent><block of operators>
Here, <block of operators> is a sequence of operators with an additional indent of 4 spaces. If the logical expression evaluates to true, the block of operators is executed; otherwise, it is not. Nested conditional operators will have an indent of 8 spaces, and so on.
The loop operator in "Phigon" is structured as follows:
<loop operator> ::=
while <logical expression>:
<indent><block of operators>
As with the conditional operator, <block of operators> is a sequence of operators with an additional indent of 4 spaces. The block of operators is repeatedly executed as long as the logical expression evaluates to true.
Finally, a "Phigon" program consists of a block of assignment operators, conditional operators, and loop operators:
<block of operators> ::= <operator> | <operator> <block of operators>
<operator> ::= <assignment operator> | <conditional operator> | <loop operator>
Your task is to determine the final values of variables after the program execution and count the number of times each of the following operations is performed: =, +, - (both binary and unary), *, <=, >=, <, >, ==, !=, and, not, or.
Input
The input file contains a "Phigon" program, with each instruction on a separate line. There are no empty lines. Each line is no longer than 500 characters, and the program contains no more than 5000 instructions. It is guaranteed that all intermediate calculation values and numerical constants in the program are strictly less than 10^500 in absolute value.
It is guaranteed that each variable is defined in an assignment operator before being used in arithmetic expressions.
Output
Output the number of times each operation was performed in the format: for each operation, output a line operation: c, where c is the count of how many times the operation was called. List the operations in lexicographical order (note the second example).
Then, output the line "total N operations", where N is the total number of operations performed. It is guaranteed that the total number of operations does not exceed 200000.
Finally, output the values of variables after the program execution in the format Variable name: v, where v is the value of the variable, listed in lexicographical order of variable names.