Robbie Can't Do Math
Robbie the Ram has a grade 1 math test tomorrow and is currently practicing review questions. However, he is very lazy and he doesn't want to actually do the questions. So he wants you to write a program for him that can calculate a math expression \(S\). However, since he is in grade 1, there is no multiplication or division, only addition, subtraction, and parentheses.
Constraints
\(1 \le |S| \le 3\times10^{5}\)
\(S\) contains spaces, +, -, (, ), and numbers.
There will be no two operations placed side by side. All parentheses will be placed in a way that is syntactically valid.
Input Specification
The first line of input will contain \(S\).
Output Specification
Output the result of evaluating the expression.
Sample Input 1
1+2
Sample Output 1
3
Sample Input 2
( 1 + 2 )- ( 2 + 5)
Sample Output 2
-4
Sample Input 3
(1+(4+5+2)-3)+(6+8)
Sample Output 3
23
Sample Input 4
-(6 7 + 6 7)
Sample Output 4
-134
Explanation for Sample 4
The subtraction operator may be used as an unary operator. However, the addition operator will not be used as one.
Comments
one liner in python
67