Who doesn’t love parentheses?
Sashka stumbled upon a bracket sequence of parentheses, from which are opening parentheses and are closing parentheses. She defines the bracket sequence’s clumsiness as the minimum number of required swaps of elements to turn it into a regular parentheses sequence. The regular parentheses sequences follow these rules:
- The empty sequence is a regular parentheses sequence.
- is a regular non-empty parentheses sequence iff two regular sequences and exist such that , where denotes the operation concatenation of two sequences.
Task
Sashka wants to know the clumsiness for such sequences , where the -th of them consists of all the elements in from position to inclusive. It is guaranteed that every sequence consists of equal number of opening and closing parentheses. Write a program which answers the questions.
Input data
The first line of the standard input contains the three integers , and , which describe the number of opening parentheses in the sequence, the number of questions and the number of the subtask that the test is from. The second line contains parentheses, , , , respectively. The last lines of the standard input contain the integers and , which describe the positions for the -th question.
Output data
On the standard output print one number on each line, the -th number being the minimum number of required swaps to turn into a regular parentheses sequence.
Constraints and clarifications
- All questions are different from one another.
# | Score | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 5 | , , , |
3 | 10 | , , , |
4 | 10 | , , , |
5 | 15 | , , , |
6 | 15 | Special scoring, see below |
7 | 45 | No additional constraints |
- Only in the sixth subtask, one test is considered to be successfully passed by your solution, if you have found correctly all answers that are . For the other questions in the test (for which the correct answers is not ), it is only needed that the printed number is a integer in the interval .
Example 1
stdin
3 1 1
)())((
1 6
stdout
1
Explanation
)())((
(())()
Example 2
stdin
5 10 1
()))(()(()
2 9
6 7
1 10
3 8
7 10
3 10
9 10
4 7
4 5
3 6
stdout
2
0
1
1
1
1
0
1
1
1