#d1607. 括号序列
括号序列
Bracket Sequence
Problem Source
Problem Description
A valid bracket sequence is defined as follows:
- The empty sequence is a valid bracket sequence.
- If is a valid bracket sequence, then is a valid bracket sequence.
- If and are both valid bracket sequences, then is a valid bracket sequence.
You are given a bracket sequence. Count how many of its non-empty substrings are valid bracket sequences.
Note: for convenience, five samples are provided, but they are placed in a single box.
Input Format
A string .
Output Format
The number of non-empty substrings that are valid bracket sequences.
Sample Input
(
()
()()
(()
(())
Sample Output
0
1
3
1
2
Constraints