Sequence and Queries 13

Maintain an array under range add, range multiply, and range assign modulo 1e9+7, answering range sum queries.

Hard8Segment treeLinked listMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a sequence A1,A2,,ANA_1, A_2, \dots, A_N of length NN. Write a program that processes the following four kinds of queries.

  • 1 x y v: for every ii with xiyx \le i \le y, replace AiA_i with (Ai+v)mod(109+7)(A_i + v) \bmod (10^9+7).
  • 2 x y v: for every ii with xiyx \le i \le y, replace AiA_i with (Ai×v)mod(109+7)(A_i \times v) \bmod (10^9+7).
  • 3 x y v: for every ii with xiyx \le i \le y, replace AiA_i with vv.
  • 4 x y: print (i=xyAi)mod(109+7)\left(\sum_{i=x}^{y} A_i\right) \bmod (10^9+7).

The modulus is always 109+710^9+7, and mod\bmod is the remainder operation.

Input

The first line contains the length NN of the sequence. (1N1000001 \le N \le 100000)

The second line contains A1,A2,,ANA_1, A_2, \dots, A_N. (1Ai1091 \le A_i \le 10^9)

The third line contains the number of queries MM. (1M1000001 \le M \le 100000)

Each of the next MM lines contains one query. (1xyN1 \le x \le y \le N, 1v1091 \le v \le 10^9)

Output

For each query of type 4, print the answer on its own line, in the order the queries are given.