#K15011. Balanced Brackets

    ID: 24262 Type: Default 1000ms 256MiB

Balanced Brackets

Balanced Brackets

You are given a string s consisting of characters which are one of the following brackets: ( ), [ ], { } and . Your task is to determine whether the input string is balanced.

A string is considered balanced if:

  • Every opening bracket has a corresponding closing bracket.
  • The pairs of brackets are properly nested.

Mathematically, for an opening bracket O and closing bracket C, the relation can be expressed in LaTeX as: \( O \; \text{matches} \; C \).

For example, the string [()]{}{[()()]()} is balanced and should output YES, while the string [(]) is not balanced and should output NO.

inputFormat

The input consists of a single line string s containing only bracket characters: ( ), [ ], { }, and . The string may be empty.

outputFormat

Output a single line containing either YES if the string is balanced or NO if it is not.

## sample
[()]{}{[()()]()}
YES

</p>