CF785D.Anton and School - 2

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ss of length nn is an RSBS if the following conditions are met:

  • It is not empty (that is n0n≠0 ).
  • The length of the sequence is even.
  • First charactes of the sequence are equal to "(".
  • Last 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 ss . Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of ss is a string that can be obtained from ss 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 109+710^{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!

输入格式

The only line of the input contains a string ss — 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 200000200000 .

输出格式

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

输入输出样例

  • 输入#1

    )(()()
    

    输出#1

    6
    
  • 输入#2

    ()()()
    

    输出#2

    7
    
  • 输入#3

    )))
    

    输出#3

    0
    

说明/提示

In the first sample the following subsequences are possible:

  • If we delete characters at the positions 11 and 55 (numbering starts with one), we will get the subsequence "(())".
  • If we delete characters at the positions 11 , 22 , 33 and 44 , we will get the subsequence "()".
  • If we delete characters at the positions 11 , 22 , 44 and 55 , we will get the subsequence "()".
  • If we delete characters at the positions 11 , 22 , 55 and 66 , we will get the subsequence "()".
  • If we delete characters at the positions 11 , 33 , 44 and 55 , we will get the subsequence "()".
  • If we delete characters at the positions 11 , 33 , 55 and 66 , we will get the subsequence "()".

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

首页