suru1206's blog

By suru1206, history, 5 weeks ago, In English

Sourav has an array A consisting of N integers(1-based indexing), He asks you to perform the following operation M times: for i=2 to n;

A[i]=A[i]+A[i-1]

Your task is to find the xth element of the array(i.e., A[x]) after performing the above operation M times. As the answer could be large, please output it modulo 10^9+7.

INPUT The First line of input contains an integer T denoting the number of test cases. The first line of each test case contains three space-separated integers-N,x,M-denoting the size of the array ,index of the element you have to find, and the amount of times you need to repeat operation before finding the element ,respectively.The second line contains N space-separated integers A1,A2,...,A[N].

OUTPUT For each test case,output a single line containing one integer : A[x]modulo 10^9+7.

CONSTRAINTS

1<=T<=10

1<=x<=N<=10^5

1<=M<=10^18

1<=A[i]<=10^18

EXAMPLE

Input:

2

3 2 3

1 2 3

3 3 3

1 2 3

Output:

5

15

 
 
 
 
  • Vote: I like it
  • -6
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Help me to do in O(n) time complexity.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can you provide some link or source of the problem?