#K72162. Final Variable State
Final Variable State
Final Variable State
You are given a sequence of commands that modify the state of a variable. Initially the variable is set to 0. Each command is a string in the form operation operand
where operation is one of the following:
- add: add the given integer to the variable.
- subtract: subtract the given integer from the variable.
- multiply: multiply the variable by the given integer.
- divide: perform integer division of the variable by the given integer (i.e. floor division).
The operations are executed sequentially starting from 0. Formally, if the operations are denoted by \( op_1, op_2, \ldots, op_n \) and their corresponding integer values by \( a_1, a_2, \ldots, a_n \), then the final state \( S \) is computed as:
\( S = (((0 \; op_1 \; a_1) \; op_2 \; a_2) \; \ldots \; op_n \; a_n) \)
Your task is to compute and output the final value of the variable after executing all commands.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains an integer \( n \) denoting the number of commands.
- Each of the next \( n \) lines contains a command in the format
operation operand
.
It is guaranteed that if \( n = 0 \), no command lines follow.
outputFormat
Output the final state of the variable to standard output (stdout) as a single integer.
## sample3
add 5
subtract 3
multiply 2
4