Maksym and the Time Machine#2937

Maksym and the Time Machine

1 second
128 megabytes
Easy (≈1000)

Mom gave Maksym a time machine, but it only works with a special array of length built into it. This machine can restore the array to its state at any previous moment in time. The array isn't ordinary: it is quite unique.

Maksym can select three numbers — , , and (1 \leq i \leq j \leq n, -1000 \leq d \leq 1000) — and magically add to all elements of the array from index to . While Maksym experiments with his array, his mom occasionally asks him about the sum of the numbers in the array from index to . Maksym can answer these questions easily, but can you?

Input

The first line contains two integers and (1 \leq n, q \leq 10^5) — the number of elements in the array and the total number of operations and queries.

The second line contains integers a_1, a_2, \ldots, a_n (-1000 \leq a_i \leq 1000) — the initial state of the array.

Each of the next lines describes an operation or query, beginning with one of the following symbols:

  • t — time machine operation, followed by an integer (1 \leq i), indicating that the array should be reverted to its state immediately before the -th operation or query (operations and queries are numbered from the beginning, starting at ). It is guaranteed that will not exceed the current operation number.

  • + — addition operation, followed by , , and (1 \leq i \leq j \leq n, -1000 \leq d \leq 1000), meaning that is added to all elements a_k with i \leq k \leq j.

  • ? — query operation, followed by and (1 \leq f, t \leq n): output the sum of all elements from index to .

Output

For each query (?), print the sum of elements in the array from index to (inclusive) on a separate line.

Examples

Example 1

Loading
Loading