#C13034. Valid Parentheses Checker

    ID: 42528 Type: Default 1000ms 256MiB

Valid Parentheses Checker

Valid Parentheses Checker

You are given a mathematical expression as a string that may contain various types of parentheses: ( ), [ ], and { }. Your task is to determine whether the parentheses in the expression are balanced and correctly nested. For example, an expression like 3+(2-5)*(6/3) is valid, whereas 3+{2-5]*[6/3} is not.

The balance condition can be mathematically represented in LaTeX as follows:

$$\text{A sequence } S \text{ is valid if } \forall i, \quad S[i] \in \{ '(', '[', '{' \} \Rightarrow \exists j > i \text{ such that } S[i] \text{ matches } S[j]\text{, and the nesting is correct.} $$

Determine if the given expression contains balanced parentheses.

inputFormat

The input is a single line string representing the expression. The expression may include digits, arithmetic operators, and the parentheses characters ( ), [ ], and { }. All input should be read from standard input (stdin).

outputFormat

Output a single line: True if the expression’s parentheses are balanced; otherwise, False. The output should be written to standard output (stdout).

## sample
3+(2-5)*(6/3)
True