CSES - E4590 2020 4 - Sums
  • Time limit: 1.00 s
  • Memory limit: 512 MB

There is an array of nn numbers, indexed 1,2,,n1, 2, \ldots, n. Your task is to implement a data structure which has the following operators:

  1. Increase every number in the range [a,b][a,b] by xx
  2. Set every number in the range [a,b][a,b] to be xx
  3. Compute the sum of numbers in the range [a,b][a,b]

Input

The first line of the input has single integer nn, the size of the array.

The next line has nn integers v1,v2,,vnv_1, v_2, \ldots, v_n, the original content of the array.

Next line has single integer qq, the number of queries.

The rest qq lines each describe one query:

If the query type is 1, the line is of form "1 aa bb xx". This means that every number in the range [a,b][a,b] needs to be increased by xx.

If the query type is 2, the line is of form "2 aa bb xx". This means that every number in the range [a,b][a,b] needs to be set to xx.

If the query type is 3, the line is of form "3 aa bb". This means that you have to count the sum of numbers in the range [a,b][a,b].

Output

For each query of type 3, output the sum, one per line.

Limits

  • 1n1051 \le n \le 10^5
  • 106vi106-10^6 \le v_i \le 10^6
  • 1q1051 \le q \le 10^5
  • 1abn1 \le a \le b \le n
  • 106x106-10^6 \le x \le 10^6

Example

Input:

5
2 3 1 1 5
5
3 3 5
1 2 4 2
3 3 5
2 2 4 5
3 3 5

Output:

7
11
15