Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/stack-postfiks-ifoda

Evaluating a postfix expression

Medium 1000 ms 128 MB 51%
Share

A correct expression in postfix notation is given: in it an operation sign is written after its two operands, and a b - means $a - b$. For example, the expression $(3 + 4) * 2$ is written as 3 4 + 2 *. The operations are +, -, *. Find the value of the expression.

Elements of the postfix expression and the intermediate values after each operation in cells one above another

Input

One line with integers and operation signs separated by spaces.

Output

One integer — the value of the expression.

Note

The expression has at most $3 * 10^{5}$ numbers and operation signs in total
Each number is from $0$ to $100$
Every intermediate value and the answer are from $-10^{18}$ to $10^{18}$

Examples

Input #1
3 4 + 2 *
Output #1
14
Input #2
5 1 2 + 4 * + 3 -
Output #2
14

Sign in to submit a solution

Signing up is free and takes a minute.