1271: Brackets SequenceTime Limit: 1 Sec Memory Limit: 128 Mb Submitted: 444 Solved: 220
Let us define a regular brackets sequence in the following way:
1. Empty sequence is a regular sequence.
2. If S is a regular sequence, then (S) is a regular sequence.
3. If A and B are regular sequences, then AB is a regular sequence.
For example, these sequences of characters are regular brackets sequences: (), (()), ()(), ()(()), ((())())().
And all the following character sequences are not: (, ), ((), ()), ())(, (()(, ()))().
A sequence of characters '(' and ')' is given. You can insert only one '(' or ')' into the left of the sequence, the right of the sequence, or the place between any two adjacent characters, to try changing this sequence to a regular brackets sequence.
The first line has a integer T (1 <= T <= 200), means there are T test cases in total.
For each test case, there is a sequence of characters '(' and ')' in one line. The length of the sequence is in range [1, 105].
For each test case, print how many places there are, into which you insert a '(' or ')', can change the sequence to a regular brackets sequence.
What's more, you can assume there has at least one such place.
4 ) ()) (()(()) ((())())(()
1 3 7 3