Parentheses

Time limit: 0.3s Memory limit: 256MB Input: Output:

Who doesn’t love parentheses?

Sashka stumbled upon a bracket sequence S=s1s2s2NS = s_1 s_2 \dots s_{2N} of 2N2N parentheses, from which NN are opening parentheses and NN 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.
  • SS is a regular non-empty parentheses sequence iff two regular sequences AA and BB exist such that S=( + A + ) + BS = \text{( + } A \text{ + ) + } B, where +\text{+} denotes the operation concatenation of two sequences.

Task

Sashka wants to know the clumsiness for QQ such sequences T1,T2,,TQT_1, T_2, \dots, T_Q, where the ii-th of them Ti=sLisLi+1sRiT_i = s_{L_i} s_{L_{i+1}} \dots s_{R_i} consists of all the elements in SS from position LiL_i to RiR_i inclusive. It is guaranteed that every sequence TiT_i consists of equal number of opening and closing parentheses. Write a program which answers the QQ questions.

Input data

The first line of the standard input contains the three integers NN, QQ and GG, 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 2N2N parentheses, s1s_1, s2s_2, \dots, s2Ns_{2N} respectively. The last QQ lines of the standard input contain the integers LiL_i and RiR_i, which describe the positions for the ii-th question.

Output data

On the standard output print one number on each line, the ii-th number being the minimum number of required swaps to turn TiT_i into a regular parentheses sequence.

Constraints and clarifications

  • 1N,Q21051 \leq N, Q \leq 2 \cdot 10^5
  • 1Li<Ri2N1 \leq L_i < R_i \leq 2N
  • All questions are different from one another.
# Score Constraints
1 0 Examples
2 5 Q=1Q = 1, N4N \leq 4, L1=1L_1 = 1, R1=2NR_1 = 2N
3 10 Q=1Q = 1, N100N \leq 100, L1=1L_1 = 1, R1=2NR_1 = 2N
4 10 Q=1Q = 1, N1 000N \leq 1 \ 000, L1=1L_1 = 1, R1=2NR_1 = 2N
5 15 Q=1Q = 1, N2105N \leq 2 \cdot 10^5, L1=1L_1 = 1, R1=2NR_1 = 2N
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 00. For the other questions in the test (for which the correct answers is not 00), it is only needed that the printed number is a integer in the interval [1,1018][1, 10^{18}].

Example 1

stdin

3 1 1
)())((
1 6

stdout

1

Explanation

)())(( \rightarrow (())()

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

Log in or sign up to be able to send submissions!