The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function.
The Zigag's sequence with the zigzag factor z is an infinite sequence S_{i}^{z} (i ≥ 1; z ≥ 2), that is determined as follows:
Operation means taking the remainder from dividing number x by number y. For example, the beginning of sequence S_{i}^{3} (zigzag factor 3) looks as follows: 1, 2, 3, 2, 1, 2, 3, 2, 1.
Let's assume that we are given an array a, consisting of n integers. Let's define element number i (1 ≤ i ≤ n) of the array as a_{i}. The Zigzag function is function , where l, r, z satisfy the inequalities 1 ≤ l ≤ r ≤ n, z ≥ 2.
To become better acquainted with the Zigzag sequence and the Zigzag function, the wizard offers you to implement the following operations on the given array a.
Explore the magical powers of zigzags, implement the described operations.
The first line contains integer n (1 ≤ n ≤ 10^{5}) — The number of elements in array a. The second line contains n space-separated integers: a_{1}, a_{2}, ..., a_{n} (1 ≤ a_{i} ≤ 10^{9}) — the elements of the array.
The third line contains integer m (1 ≤ m ≤ 10^{5}) — the number of operations. Next m lines contain the operations' descriptions. An operation's description starts with integer t_{i} (1 ≤ t_{i} ≤ 2) — the operation type.
You should execute the operations in the order, in which they are given in the input.
For each Zigzag operation print the calculated value of the Zigzag function on a single line. Print the values for Zigzag functions in the order, in which they are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
5
2 3 1 5 5
4
2 2 3 2
2 1 5 3
1 3 5
2 1 5 3
5
26
38
Explanation of the sample test:
Name |
---|