#C14416. Evaluate Mathematical Expression

    ID: 44063 Type: Default 1000ms 256MiB

Evaluate Mathematical Expression

Evaluate Mathematical Expression

You are given a mathematical expression containing non-negative integers, the operators + and -, and parentheses (). Your task is to evaluate the expression by following standard arithmetic rules and taking the grouping defined by parentheses into account.

The expression may include multiple-digit numbers and nested parentheses. There is no whitespace in the input.

Examples:

  • \(1+2+3 = 6\)
  • \(10-5-3 = 2\)
  • \((1+(4+5+2)-3)+(6+8) = 23\)
  • \(((2+3)-(1-(6+8))) = 18\)
  • \(3+5-2 = 6\)
  • \((3+(2-1))-((1+2)-3) = 4\)

inputFormat

The input consists of a single line containing a valid mathematical expression. The expression includes digits (0-9), the operators + and -, and parentheses (). There are no spaces in the input.

outputFormat

Output a single integer that represents the result of evaluating the expression.

## sample
1+2+3
6