6852.Bracket Sequences II

Time Limit: 1s Memory Limit: 512MB

Your task is to calculate the number of valid bracket sequences of length $n$ when a prefix of the sequence is given.

Input Format(From the terminal/stdin)

The first input line has an integer $n$ .

The second line has a string of $k$ characters: the prefix of the sequence.

  • $1 \le k \le n \le 10^6$

Output Format(To the terminal/stdout)

Print the number of sequences modulo $10^9+7$ .

Sample Input

Copy
6
(()
 \n
   \n

Sample Output

Copy
2
 \n

There are two possible sequences: (())() and (()()) .

Source: CSES, Mathematics, 2187

Submit

请先 登录

© 2025 FAQs