#K53912. Arithmetic Expression Evaluation

    ID: 29637 Type: Default 1000ms 256MiB

Arithmetic Expression Evaluation

Arithmetic Expression Evaluation

You are given arithmetic expressions that contain integers and the operators \(+, -, \times, \div\) along with nested parentheses. Evaluate each expression following the standard operator precedence. The division (\(\div\)) operator should perform integer division by truncating any decimal part.

The program must also handle error cases. If a division by zero occurs, output Division by zero error. If the expression is syntactically incorrect, output Invalid expression.

inputFormat

Input is given via stdin as multiple lines. Each line contains an arithmetic expression. The input terminates with a line that contains exactly end (which should not be processed).

outputFormat

For each valid expression line (before the termination line), output the evaluated result on a separate line to stdout. In case of an error (division by zero or invalid expression), output the corresponding error message: Division by zero error or Invalid expression.

## sample
3 + 5 * 2
(1 + 2) * 4 - 3
10 / (3 - 3 + 1)
end
13

9 10

</p>