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

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

Evaluating an expression with brackets

Medium 1000 ms 128 MB 53%
Share

A correct arithmetic expression in ordinary notation is given. It contains integers from $0$ to $100$, the operations +, -, * and the brackets (, ), with no spaces. First what is inside brackets is done, then multiplication, then addition and subtraction; operations of the same priority are done from left to right (for example, the value of 8-3-2 is $3$). Find the value of the expression. Negative numbers (like -5) are not written in the expression.

Symbols of the expression and the step-by-step evaluation: numbers and operations in cells one above another

Input

One line with the expression.

Output

One integer — the value of the expression.

Note

the length of the expression is from $1$ to $2 * 10^{5}$
each number is from $0$ to $100$, without unnecessary zeros
every intermediate value and the answer are from $-10^{18}$ to $10^{18}$

Examples

Input #1
(3+4)*2-10
Output #1
4
Input #2
2*(5-8*(1+1))
Output #2
-22

Sign in to submit a solution

Signing up is free and takes a minute.