#K44047. Balanced Parentheses Checker

    ID: 27444 Type: Default 1000ms 256MiB

Balanced Parentheses Checker

Balanced Parentheses Checker

Given a string consisting solely of the characters (, ), {, }, [ and ], determine whether the string is valid. A string is considered valid if:

  • Every opening bracket has a corresponding closing bracket of the same type.
  • Brackets are closed in the correct order.

In other words, the string is valid if it can be fully reduced by matching brackets according to the formula:

\(\text{Valid}(s) \iff s = "" \quad \text{or} \quad s = \alpha\,b\,\beta \,\text{with} \; b \; \text{being a valid pair}\)

Implement a function that checks if the input string is valid.

inputFormat

The input consists of a single line read from standard input (stdin) that contains a string of characters. The string contains only the characters (, ), {, }, [, and ]. The empty string is also allowed.

outputFormat

Output a single line to standard output (stdout) with either True if the input string is valid, or False if it is not.

## sample
()
True