Codeforces Round 404 (Div. 2)
D
Anton and School - 2
Codeforces
2300
原题
← CE →
翻译中…

As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)).

翻译中…

On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence $*s*$ of length $*n*$ is an RSBS if the following conditions are met:

翻译中…
  • It is not empty (that is $*n* ≠ 0$).
  • The length of the sequence is even.
  • First image charactes of the sequence are equal to "(".
  • Last image charactes of the sequence are equal to ")".
翻译中…

For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS.

翻译中…

Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence $*s*$. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of $*s*$ is a string that can be obtained from $*s*$ by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted.

翻译中…

Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo $10^{9} + 7$.

翻译中…

Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it!

翻译中…

Input

翻译中…

The only line of the input contains a string $*s*$ — the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed $200 000$.

翻译中…

Output

翻译中…

Output one number — the answer for the task modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In the first sample the following subsequences are possible:

翻译中…
  • If we delete characters at the positions $1$ and $5$ (numbering starts with one), we will get the subsequence "(())".
  • If we delete characters at the positions $1$, $2$, $3$ and $4$, we will get the subsequence "()".
  • If we delete characters at the positions $1$, $2$, $4$ and $5$, we will get the subsequence "()".
  • If we delete characters at the positions $1$, $2$, $5$ and $6$, we will get the subsequence "()".
  • If we delete characters at the positions $1$, $3$, $4$ and $5$, we will get the subsequence "()".
  • If we delete characters at the positions $1$, $3$, $5$ and $6$, we will get the subsequence "()".
翻译中…

The rest of the subsequnces are not RSBS. So we got $6$ distinct subsequences that are RSBS, so the answer is $6$.

翻译中…

样例

Input #1
)(()()
Output #1
6
InputCopy OutputCopy
Input #2
()()()
Output #2
7
InputCopy OutputCopy
Input #3
)))
Output #3
0
InputCopy OutputCopy
题目信息
题号
785D
时间限制
2 s
内存限制
256 MB
标签
组合数学
动态规划
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。