Reverse Polish notation (RPN) is a mathematical notation in which every operator follows all of its operands. This notation is also known as postfix notation and does not require any parentheses as long as each operator has a fixed number of operands.
For example:
The expression 2 + 4 in RPN is written as
The expression 2 * 4 + 8 in RPN is written as 2~4 * 8 +
The expression 2 * (4 + 8) in RPN is written as 2~4~8 + *
Evaluate the value of an arithmetic expression written in Reverse Polish Notation. The valid operators are +,~-,~*,~/ only. The division operator performs integer division (14~/~3 = 4). Each operand may be either an integer or another expression.
One line contains the expression written in Reverse Polish notation. The length of the expression does not exceed characters.
Print the value of the expression given in Reverse Polish notation.
Example 1
Example 2
Example 3