Problem D. Brackets

时间限制 1000 ms   内存限制 64 MB

We give the following inductive definition of a “regular brackets” sequence:
● the empty sequence is a regular brackets sequence,
● if s is a regular brackets sequence, then (s) are regular brackets sequences, and
● if a and b are regular brackets sequences, then ab is a regular brackets sequence.
● no other sequence is a regular brackets sequence

For instance, all of the following character sequences are regular brackets sequences:
(), (()), ()(), ()(())
while the following character sequences are not:
(, ), )(, ((), ((()

Now we want to construct a regular brackets sequence of length $n$, how many regular brackets sequences we can get when the front several brackets are given already.
 

输入数据

Multi test cases (about $2000$), every case occupies two lines.
The first line contains an integer $n$.
Then second line contains a string str which indicates the front several brackets.

Please process to the end of file.

[Technical Specification]
$1 \leq n \leq 1000000$
str contains only '(' and ')' and length of str is larger than 0 and no more than $n$.
 

输出数据

For each case,output answer % $1000000007$ in a single line.
 

样例输入

复制
4
()
4
(
6
()

样例输出

复制
1
2
2

样例说明

For the first case the only regular sequence is ()(). For the second case regular sequences are (()) and ()(). For the third case regular sequences are ()()() and ()(()).
         
 

提交

请先 登录

© 2025 FAQs Contact About