This page is still under construction.

Parts of this page are still being built. What you see may change.

Calculation mistake

Time limit3sMemory limit256 MB

Summary
Maintain a string of digits and plus or minus signs under range replacements, and evaluate the arithmetic value of any substring with the calculator's operator rules.
Level

Hard8 of 10

Topics
Segment tree, String, Math
Solved
No attempts yet

Problem

Suchan uses a calculator that only adds and subtracts. It has the digit buttons 0 through 9, the operator buttons + and -, an = button that shows the result, and an AC button that returns the calculator to its initial state. There is no C button that clears only the number being typed.

Type an expression in order and press =, and the screen shows the result. The numbers have no range limit, and a number may start with 0. To keep a mistyped operator from spoiling the result, the calculator follows three rules.

  1. When operators appear one after another, only the last one counts.
  2. When the expression starts with an operator, a 0 is treated as written in front of it.
  3. When the expression ends with an operator, that operator is ignored.

For example, press -15+0035-+-3- in order and then =. The calculator evaluates 0−15+35−30 - 15 + 35 - 3 and shows 17. Press only - and then =: the expression becomes 0−0-, the final - is ignored, and the result is 0.

Without a C button, one wrong digit forces Suchan to press AC and type the whole expression again. To get rid of that, he decided to build the following data structure.

There is a string SS of length NN made only of 0 through 9, +, and -. For a string XX and 1≤i≤j≤∣X∣1 \le i \le j \le |X|, let X[i..j]X[i..j] be the substring formed by concatenating the ii-th through jj-th characters of XX.

Implement a data structure that supports the two operations below.

  1. Replace: change S[a..b]S[a..b] into a new string TT of length b−a+1b - a + 1. That is, for every ii with a≤i≤ba \le i \le b, set S[i]S[i] to T[i−a+1]T[i - a + 1].
  2. Evaluate: press AC, type S[a..b]S[a..b] into the calculator, press =, and report the value shown on the screen.

Input

The first line contains the length of the string, NN (1≤N≤200 0001 \le N \le 200\,000).

The second line contains the string SS. Its length is NN.

The third line contains the number of queries, QQ (1≤Q≤300 0001 \le Q \le 300\,000).

Each of the next QQ lines contains one operation. The formats are below.

  • A replace operation is given as 1 a b T. Here aa and bb are integers with 1≤a≤b≤N1 \le a \le b \le N, and TT is a string of length b−a+1b - a + 1. The lengths of TT over all replace operations sum to at most 200 000200\,000.
  • An evaluate operation is given as 2 a b. Here aa and bb are integers with 1≤a≤b≤N1 \le a \le b \le N. At least one evaluate operation is given.

Every string in the input consists only of 0 through 9, +, and -.

Output

For each evaluate operation, print the result modulo 109+710^9 + 7 on its own line. The remainder of an integer xx modulo 109+710^9 + 7 is the value of rr for which integers qq and rr satisfy x=q(109+7)+rx = q(10^9 + 7) + r and 0≤r<109+70 \le r < 10^9 + 7.

Examples1

  1. Example 1

    Input
    10
    153+0174-1
    8
    2 1 10
    2 3 9
    1 3 8 +3-+43
    2 2 8
    1 1 8 5-221043
    2 4 9
    2 1 10
    2 2 2
    
    Expected output
    326
    177
    51
    21043
    999778968
    0