#SGM0000010. Sereja và dãy ngoặc (Sereja and Brackets)
Sereja và dãy ngoặc (Sereja and Brackets)
Sereja and Brackets
Source: Codeforces
Version: Phuoc Hung OJ Extended
You are given a bracket string of length consisting only of ( and ). For every query , find the maximum length of a correct bracket subsequence of .
A correct bracket sequence matches every opening bracket with a later closing bracket and every bracket belongs to exactly one pair.
Input
The first line contains , with .
The second line contains .
Each of the next lines contains .
Output
For every query, print the maximum correct bracket subsequence length.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: , .
- Subtask 3 — 50%: , .
Examples
Input
())(())(())(
7
1 1
2 3
1 2
1 12
8 12
5 11
2 10
Output
0
0
2
10
4
6
6
Explanation
The sample follows the operations exactly; each printed line corresponds to a query that requires output.