We are given N numbers. We have to select K of them. We also have a number M. Suppose the numbers we selected were A1,A2,A3..Ak. (note that we write these numbers in order in which they appeared in the original array). Define S=∑ki=1Ai⋅(imodM).
We have to maximize S.
Constraints :
N≤104
K≤103
|Ai|≤107
M≤107
Input Format :
In the first line, three space separated integers N,K,M are given. In the next line, N space separated integers A1,A2,A3,…An are given.
Output Format :
Print a single integer corresponding to the answer.
9*1 + 8*2 + 2*0 + 7*1 = 32