2009.Long number

Time Limit: 1s Memory Limit: 256MB

Consider the following grammar:
\lt expression \gt ::= \lt term \gt | \lt expression \gt '+' \lt term \gt \lt term \gt ::= \lt number \gt | \lt number \gt '-' \lt number \gt | \lt number \gt '(' \lt expression \gt ')' \lt number \gt ::= \lt pos_digit \gt | \lt number \gt \lt digit \gt \lt digit \gt ::= '0' | \lt pos_digit \gt \lt pos_digit \gt ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
This grammar describes a number in decimal system using the following rules:
\lt number \gt describes itself, \lt number \gt - \lt number \gt (l-r, l \le r) describes integer which is concatenation of all integers from l to r, written without leading zeros. For example, 8-11 describes 891011, \lt number \gt ( \lt expression \gt ) describes integer which is concatenation of \lt number \gt copies of integer described by \lt expression \gt , \lt expression \gt + \lt term \gt describes integer which is concatenation of integers described by \lt expression \gt and \lt term \gt .
For example, 2(2-4+1)+2(2(17)) describes the integer 2341234117171717.

You are given an expression in the given grammar. Print the integer described by it modulo 109+7.

Input Format(From the terminal/stdin)

The only line contains a non-empty string at most 105 characters long which is valid according to the given grammar. In particular, it means that in terms l-r l \le r holds.

Output Format(To the terminal/stdout)

Print single integer- the number described by the expression modulo 109+7.

Sample Input 1

Copy
8-11
    \n

Sample Output 1

Copy
891011
      \n

Sample Input 2

Copy
2(2-4+1)+2(2(17))
                 \n

Sample Output 2

Copy
100783079
         \n

Sample Input 3

Copy
1234-5678
         \n

Sample Output 3

Copy
745428774
         \n

Sample Input 4

Copy
1+2+3+4-5+6+7-9
               \n

Sample Output 4

Copy
123456789
         \n

Submit

请先 登录

© 2025 FAQs