CF730L Expression Queries

Description

A simplified arithmetic expression (SAE) is an arithmetic expression defined by the following grammar: - ::= | + | \* | () - ::= | - ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 In other words it's a correct arithmetic expression that is allowed to contain brackets, numbers (possibly with leading zeros), multiplications and additions. For example expressions "(0+01)", "0" and "1\*(0)" are simplified arithmetic expressions, but expressions "2-1", "+1" and "1+2)" are not. Given a string $ s_{1}s_{2}...s_{|s|} $ that represents a SAE; $ s_{i} $ denotes the $ i $ -th character of the string which can be either a digit ('0'-'9'), a plus sign ('+'), a multiplication sign ('\*'), an opening round bracket '(' or a closing round bracket ')'. A part $ s_{l}s_{l+1}...s_{r} $ of this string is called a sub-expression if and only if it is a SAE. You task is to answer $ m $ queries, each of which is a pair of integers $ l_{i} $ , $ r_{i} $ $ (1

Input Format

The first line of the input contains non-empty string $ s $ $ (1

Output Format

The $ i $ -th number of output should be the answer for the $ i $ -th query. If the $ i $ -th query corresponds to a valid sub-expression output the value of the sub-expression modulo $ 1000000007 (10^{9}+7) $ . Otherwise output -1 as an answer for the query. Print numbers on separate lines.