Under construction

Still being built. Things may change

Single Digit Adder

Interview

Time limit1sMemory limit128 MB

Summary
Evaluate each line as an arithmetic expression of single digits with plus, minus, and parentheses.
Level

Medium4 of 10

Topics
Stack, Recursion
Solved
No attempts yet

Problem

Write a program that evaluates expressions built from the following grammar, written roughly in BNF (Backus Naur Form).

expr ::= term | expr '+' term | expr '-' term
unary_op ::= '+' term | '-' term
term ::= '(' expr ')' | '(' unary_op ')' | literal
literal ::= [0-9]

An expression contains no whitespace. Every expression consists only of the characters (, ), +, - and the digits 0 through 9. You may assume that every expression in the input is well-formed.

Input

The input holds one expression per line, and each line ends with a newline. The length of an expression does not exceed 200. There are no blank lines, and the input continues to the end of the file.

Output

For each expression, print its integer value on its own line.

Examples1

  1. Example 1

    Input
    1
    (-2)+3
    (1-(2+3))
    (1-2+3)
    (1-(+(2-3)))
    
    Expected output
    1
    1
    -4
    2
    2