Evaluate Reverse Polish Notation

MediumStack & Queue
Next
StackMath

In Reverse Polish Notation the operator comes after its two operands, so 3 4 + means 3 + 4. Evaluate an expression written this way using the operators + - * /. Division truncates toward zero.

Input

A single line of space-separated tokens: integers (possibly negative) and the operators + - * /.

Output

Print the value of the expression.

Constraints

1 <= number of tokens <= 10^4 The expression is always valid, never divides by zero, and every intermediate value fits in 32 bits.

Example 1
Input
2 1 + 3 *
Output
9

(2 + 1) * 3 = 9.

Example 2
Input
4 13 5 / +
Output
6

13 / 5 truncates to 2, and 4 + 2 = 6.

Hints

Evaluate Reverse Polish Notation - Medium Stack & Queue Problem | Skill Shiksha