Apptica and List Operations

2

1 votes
Combinatorics, Easy, Math, Number Theory
Problem

Jhakaas has been given a list X of length L, Apptica being creative devises an operation defined as

Operate(X):
    for i = 1 to L-1 
        X[i] += X[i+1]

Apptica challenges Jhakaas to answer his Q queries. In each query, Apptica will run this operation Z times on the initial list and will ask Jhakaas to answer the value of the ith element (1 based indexing) of the list modulo 109 + 7. Jhakass is feeling too sleepy to play the game, he needs your help to win.


INPUT:

The first line of each test file contains an integer L denoting the size of the list.

The second line will contain integers Xi i.e the elements of the array X.

The third line will contain another integer Q and the next Q lines will contain i and Z, list index and the number of times the operation was performed on the initial list.


OUTPUT:

For each query, you will have to print the value of the ith index (modulo 109 + 7) in a new line .


CONSTRAINTS:

1 <= N * Q <=106

1 <= Xi <=1018

1 <= Z <= 1018

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

List values after each operation will be :-

Initial -> 1 4 4

1st  ->  5 8 4

2nd ->  13 12 4

3rd  ->  25 16 4

So, the answer is 16, 12, 25 respectively.

Editor Image

?