#C4145. Valid Parentheses Checker

    ID: 47651 Type: Default 1000ms 256MiB

Valid Parentheses Checker

Valid Parentheses Checker

Given a string s consisting only of the characters (' , '), '{' , '}', and '[' , ']', determine whether the sequence of parentheses is valid.

A string is considered valid if:

  • Every open bracket has a corresponding closing bracket of the same type.
  • Open brackets are closed in the correct order.

In other words, if we denote the set of allowed characters as \( s \in \{ '(', ')', '{', '}', '[', ']' \}^* \), the string s is valid if it can be fully reduced by matching pairs in the correct order.

An empty string is also considered valid.

inputFormat

The input consists of a single line containing the string s. The string has a length between 0 and 10^4 and contains only the characters '(', ')', '{', '}', '[' and ']'.

outputFormat

Output a single line: 'True' if the string is a valid parentheses sequence, and 'False' otherwise.## sample

()
True