#C14292. Balanced Bracket Validator

    ID: 43925 Type: Default 1000ms 256MiB

Balanced Bracket Validator

Balanced Bracket Validator

The task is to determine whether a given string containing various characters, including brackets, is balanced. Only the brackets ('(', ')', '[', ']', '{', '}' ) affect the decision. A sequence is considered balanced if every opening bracket has a corresponding closing bracket in the correct order.

In other words, for a string \( S \), it is balanced if and only if, after ignoring all non-bracket characters, every opening bracket \( x \) is closed by its corresponding closing bracket \( y \) in a last-in-first-out (LIFO) order.

For example:

  • Input: ()    Output: True
  • Input: [{()}]    Output: True
  • Input: [a(b{c}d]e    Output: False

inputFormat

The input consists of a single line containing a string. The string may contain letters, digits, spaces, and punctuation, but only the bracket characters ('(', ')', '[', ']', '{', '}') are considered when checking for balance.

outputFormat

Output a single line: True if the bracket sequence is balanced, and False otherwise.

## sample
()
True