406813: GYM102565 B Broken Python
Description
Jimmy was messing around with the $$$eval()$$$ function in python (he's too lazy to use a calculator), and he noticed that for some inputs he's running into issues with the recursion stack and hard-coded memory limits.
While he's desperately searching Stack Overflow for a solution to his problem, give him a hand and evaluate some expressions for him.
InputThe input consists of one line with the length $$$s \leq 10^5$$$ with integers and symbols. There are no white-space characters.
The allowed symbols are +, -, *, /, ^{}, (, ). As a reminder, the order of the operations is PEMDAS: parenthesis ('(', ')'), exponents ('^{}'), multiplication ('*'), division ('/'), addition ('+'), subtraction ('-'). For operations with the same priority($$$+-$$$, $$$*/$$$) we evaluate left to right.
For every integer $$$x$$$ in the input, $$$-10^9 < x < 10^9$$$.
If there are any expressions of the form $$$a$$$^{}$$$b$$$ in the input, we guarantee $$$b$$$ is a positive integer and not an expression.
Moreover, it is guaranteed that all unary operators are surrounded by parantheses.
OutputYou should output the result to the given mathematical expression. We guarantee that $$$-10^9 < result < 10^9$$$ and that $$$result$$$ is an integer, but the intermediate results are unbounded and could be rational numbers.
ExamplesInput1+1-1Output
1Input
35^66*0/35Output
0Input
(1/2)*2Output
1