A bracket string is defined as follows.
- The empty string is a bracket string.
- If S is a bracket string, then (S) is a bracket string.
- If S and T are bracket strings, then ST is a bracket string.
- Every bracket string is built by these three rules alone.
For example, ()() and ((()))(()) are bracket strings, while )((), (((((, and ()) are not.
Given a string S, write a program that counts how many different bracket strings appear among the substrings of S. A substring is a contiguous block cut out of S, the empty string is not counted, and a string that occurs at several positions is counted once.