ARRHUDAI - Array with Hudai Calculation

no tags 

You will be given an array A with N integers A[1…N]. You will also be given two integers P and K. You need to find a value X [ X can be any value from array A] for which this function will be maximized:

formula

Here ABS means Absolute Value. For example: ABS(-1) is 1, also ABS(1) means 1.

Here MOD means Modulo Operation. W MOD Y will give you the remainder after dividing W by Y.

And X is any value from the array A.

But we don’t have interest in X, as there will be several X for which the value will be maximized. So we just want the maximum value. Can you find it for us as you are a great programmer on SPOJ?

Input

Input starts with an integer T (≤ 5), denoting the number of test cases.

Each case starts with a line containing three integers N, P and K. Then the next line will be consisting of N integers.

1 <= N <= 100000

1 <= P <= 100

1 <= K <= 1000000009

1 <= A[i] <= 2000

Output

For each case, print the case number and the maximum value for the above function with respect to array A.

Sample

Input
2
3 1 10
3 1 2
3 2 10
3 1 2

Output
Case 1: 3
Case 2: 5

N.B: Dataset is huge. Use faster IO like Scanf, Printf


hide comments
hodobox: 2017-10-15 00:06:38

Image is missing - seems like problem is currently completely unsolvable.

Re: Fixed it.

Last edit: 2018-03-07 04:10:49
wisfaq: 2014-06-30 00:11:01

Can someone explain to me what "Hudai calculation" means?

Reply: LOL, its in Bangla Language Actually, which means "Unnecessary Calculation" in English. :)

Last edit: 2014-06-30 10:59:03
Francky: 2014-06-30 00:11:01

Typo : "You need to find a value for which...". X should be here, isn't it ?

Edit: Updated, sorry for that.

--Francky--> A new one : "can any" → "can be any" ;-)

Last edit: 2014-06-26 13:31:17
Mitch Schwartz: 2014-06-30 00:11:01

The inner mod K is redundant.

Reply: I know , just to be careful.. :D

Last edit: 2014-06-26 06:59:32

Added by:Faiyaz
Date:2014-06-25
Time limit:0.300s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem