"When" is an event-driven language for machine control. It has only three statements: Set, Print, and the compound When clause. Its grammar is as follows (keywords and variable names are case-insensitive):
PROGRAM := WHEN | PROGRAM WHEN
WHEN := 'when ' EXPRESSION EOL STATEMENTS 'end when' EOL
STATEMENTS := STATEMENT | STATEMENTS STATEMENT
STATEMENT := PRINT | SET
PRINT := 'print ' EXPRESSION_LIST EOL
SET := 'set ' ASSIGNMENT_LIST EOL
EXPRESSION_LIST := EXPRESSION | EXPRESSION_LIST ',' EXPRESSION
ASSIGNMENT_LIST := ASSIGNMENT | ASSIGNMENT_LIST ',' ASSIGNMENT
ASSIGNMENT := VARIABLE '=' EXPRESSION
EXPRESSION := '(' EXPRESSION OP EXPRESSION ')' | VARIABLE | NUMBER
OP := '<' | '+' | '-' | 'and' | 'or' | 'xor'
VARIABLE := '$' NOT_DOLLAR_STRING '$'
NUMBER := DIGIT | NUMBER DIGIT
DIGIT := '0' | .. | '9'
NOT_DOLLAR_STRING := any sequence of printing characters (including blanks)
that does not contain a $ symbol.
Any string enclosed in single quotes is treated literally. EOL is the end of line.
In words, a program is a list of When blocks, and each block contains Set and Print statements. Case is ignored for keywords and variable names. Spaces are allowed before or after any literal, except inside a number. Spaces are allowed inside variable names, and each non-empty run of spaces is treated as a single underscore, so the following all refer to the same variable:
$Remote Switch#1$
$Remote_Switch#1$
$Remote switch#1$
All variable and literal values are integers between -1000000000 and 1000000000, inclusive. All variables are global and start at zero. You are guaranteed that no expression ever evaluates to a value outside this range. The logical operators return 0 for false and 1 for true, and treat any nonzero value as true.
Running a When program means executing all active When clauses until none remain active. The active list of When clauses starts empty; then the following steps repeat:
In other words, inactive When conditions are evaluated to decide which clauses join the active list. Then one statement (Set or Print) is executed from the current active When clause. If it was that clause's last statement, the clause leaves the active list. On the next iteration, one statement is executed from the next active When clause, and so on.
A Set statement performs all of its assignments simultaneously, so
set $x$=$y$,$y$=$x$
swaps the values of $x$ and $y$. The same variable may not appear twice on the left-hand side of one Set statement (so set $x$=1,$x$=2 is illegal).
A Print statement evaluates the given expressions and prints them separated by commas, followed by a newline. So
print 1,(2+3)
produces the line
1,5
in the output.
The input is a single, syntactically correct program. You may assume the program executes no more than 100000 Set statements and no more than 100000 Print statements.
Print the output produced by executing the given program.