Distinct valid bracket subsequences

Count distinct non-empty balanced bracket strings that appear as subsequences of a given bracket string of length at most 100, modulo 1,000,000,007.

Medium7Dynamic programmingStringCombinatoricsImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

A valid bracket string is defined recursively.

  • The empty string "" is a valid bracket string.
  • If XX and YY are valid bracket strings, then XYXY is a valid bracket string.
  • If XX is a valid bracket string, then (X)(X) is a valid bracket string.
  • Every valid bracket string can be built with the rules above.

"()", "()()()", "(()())" and "(((())))" are all valid bracket strings.

A string TT is a subsequence of a string SS when you can delete some characters of SS and obtain TT. Deleting none of them or all of them is allowed. The remaining characters keep their original order. For example, "bdf" is a subsequence of "abcdefg".

You are given a string SS made only of '(' and ')'. Write a program that counts how many distinct valid bracket strings occur among the non-empty subsequences of SS. Two subsequences that spell the same string count as one, even when they delete different positions.

Input

The first line contains the string SS. It consists only of '(' and ')', and its length is between 11 and 100100.

Output

Print the number of distinct valid bracket strings among the non-empty subsequences of SS, modulo 1,000,000,007.