#K60502. Balanced Brackets

    ID: 31100 Type: Default 1000ms 256MiB

Balanced Brackets

Balanced Brackets

Given a string consisting solely of the characters ( ) [ ] { } < >, determine whether the sequence of brackets is balanced. A string is considered balanced if every opening bracket has a corresponding closing bracket in the correct order. For example, the string ([{}]) is balanced, whereas ([)] is not.

Formally, let \( S \) be the input string. The string is balanced if it satisfies the following conditions:

  • Every opening bracket \( x \) in \( S \) is eventually closed by a corresponding closing bracket \( y \) where the relation is defined as \( ( \leftrightarrow ) \), \( [ \leftrightarrow ] \), \( { \leftrightarrow } \), \( \).
  • Brackets must be closed in the correct order (i.e., proper nesting).

Your task is to write a program that reads such a string from standard input and prints True if the string is balanced, and False otherwise.

inputFormat

The input consists of a single line containing the string \( S \), which is a sequence of bracket characters. The string may be empty.

Input Example:

([{}])

outputFormat

Output a single line: True if the input string is balanced, and False otherwise.

Output Example:

True
## sample
([{}])
True