#C13166. Balanced Parentheses Checker

    ID: 42674 Type: Default 1000ms 256MiB

Balanced Parentheses Checker

Balanced Parentheses Checker

You are given a string s consisting of characters that include parentheses ( ), square brackets [ ], and curly braces { } along with other characters. Your task is to determine if the string is balanced.

A string is considered balanced if:

  • Every opening symbol has a corresponding closing symbol, and
  • The pairs of parentheses are properly nested.

Formally, if you denote the set of bracket symbols by \(\{ (, ), [, ], {, } \}\), then the string s is balanced if it can be reduced according to the following rule: \[ \text{if } s = s_1 \[\text{opening}\] s_2 \[\text{closing corresponding to the opening}\] s_3, \text{ then } s \text{ is balanced if } s_2 \text{ is balanced and } s_1, s_3 \text{ are also balanced.} \]

For example:

  • ( { [ ] } ) is balanced.
  • ( { [ ) ] } is not balanced.

inputFormat

The input consists of a single line containing the string s. The string may contain spaces and other printable characters. Read the input from standard input (stdin).

outputFormat

Output a single line: True if the string is balanced or False otherwise. Write the output to standard output (stdout).

## sample
({[]})
True