#C3254. Valid Parentheses Check
Valid Parentheses Check
Valid Parentheses Check
Given a string s consisting of only the characters '(' and ')', determine whether the sequence is a valid parentheses expression.
A parentheses sequence is considered valid if every opening parenthesis '(' has a corresponding closing parenthesis ')' and they are correctly nested. In formal terms, for every prefix of the string, the number of '(' is not less than the number of ')', and the total number of '(' equals the total number of ')'. This can be expressed in \(\LaTeX\) as:
$$\forall \text{ prefixes } p \text{ of } s,\ \#(p) - \#)(p) \ge 0 \quad \text{and} \quad \#(s) = \#)(s).$$
inputFormat
The input is read from standard input (stdin) and consists of a single line containing the string s composed only of the characters '(' and ')'.
outputFormat
Output a single line to standard output (stdout): "Yes" if the input string is a valid parentheses sequence, or "No" if it is not.
## sample()
Yes