Under construction

Still being built. Things may change

Mental Arithmetic Board Sum

Interview

Time limit1sMemory limit512 MB

Summary
Given an array, apply point assignments and right cyclic shifts, and print the sum of the board after each command.
Level

Easy3 of 10

Topics
Array, Simulation
Solved
No attempts yet

Statement

The jury chair of a mental arithmetic championship came up with a new task. Initially nn integers a1,a2,…,ana_1, a_2, \ldots, a_n are written on the board. After that, the contestant must execute commands of two types:

  1. Erase the ii-th number and write xx in its place. The numbers become a1,…,ai−1,x,ai+1,…,ana_1, \ldots, a_{i-1}, x, a_{i+1}, \ldots, a_n.
  2. Cyclically shift the sequence to the right by kk. The numbers become an−k+1,…,an,a1,…,an−ka_{n-k+1}, \ldots, a_n, a_1, \ldots, a_{n-k}.

After each command, the contestant must compute the sum of all numbers on the board and report it to the jury. The jury members must compute the required sums themselves to check the answers.

Input

The first line contains an integer nn, the number of integers initially on the board (2≤n≤1052 \leq n \leq 10^5).

The second line contains nn integers separated by spaces: a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109-10^9 \leq a_i \leq 10^9).

The third line contains an integer qq, the number of commands (1≤q≤1051 \leq q \leq 10^5).

Each of the next qq lines contains one command in one of the following formats:

  • 1 i x: replace the ii-th number with xx (1≤i≤n1 \leq i \leq n; −109≤x≤109-10^9 \leq x \leq 10^9).
  • 2 k: cyclically shift the sequence to the right by kk (1≤k<n1 \leq k < n).

Output

Print qq lines, each containing one integer. The ii-th line is the sum of the numbers on the board after the first ii commands.

The answer can be large, so a 64-bit integer type is needed: int64 in Pascal, long long in C++, long in Java.

Hint

In the example from the statement, the initial sequence is 4,1,2,1,5,34, 1, 2, 1, 5, 3. After the first command, the sequence is shifted right by 3 elements, giving 1,5,3,4,1,21, 5, 3, 4, 1, 2 with sum 1+5+3+4+1+2=161 + 5 + 3 + 4 + 1 + 2 = 16. The second command replaces the third element with 1010, giving 1,5,10,4,1,21, 5, 10, 4, 1, 2 with sum 2323. The third command replaces the fourth element with 44. It is already 44, so the sequence does not change and the sum stays 2323. The fourth command shifts the sequence right by 1, giving 2,1,5,10,4,12, 1, 5, 10, 4, 1. The sum does not change. The fifth command replaces the first element with −10-10, giving −10,1,5,10,4,1-10, 1, 5, 10, 4, 1 with sum −10+1+5+10+4+1=11-10 + 1 + 5 + 10 + 4 + 1 = 11.

Examples2

  1. Example 1

    Input
    6
    4 1 2 1 5 3
    5
    2 3
    1 3 10
    1 4 4
    2 1
    1 1 -10
    
    Expected output
    16
    23
    23
    23
    11
    
  2. Example 2

    Input
    3
    1000000000 1000000000 1000000000
    3
    1 2 999999999
    2 2
    1 2 999999999
    
    Expected output
    2999999999
    2999999999
    2999999998