SOLVE
LATER
Consider the following function which takes two integers P,Q and an array as input and returns the score of the array.
function Score(int P, int Q, int arr[]){
if(arr contains duplicate elements) return 0;
int ret = 0;
int n = arr.size();
for(int i=0;i<n;i++){
ret += pow(P,arr[i])%Q;
}
return ret;
}
You are given the integers P and Q and N integer arrays. You need to find the maximum possible value the above mentioned function can return, upon merging a maximum of 2 arrays among the given arrays.
Input
The first line contains three space separated integers N, P and Q
Each of the next N lines describe a single array. The first integer on each of those lines contains a single integer X denoting the size of the array. The next X integers represent the elements of the array.
Output:
Print the required answer on a single line.
Constraints
\( 1 \le N \le 100000 \)
\( 1 \le P \le 10000 \)
\( 1 \le Q \le 100000 \)
\( \le 1 \le S_i \le 18 \) , where \(S_i\) represents the size of the \(i^{th}\) array.
All the elements in the arrays are between \([1-18]\) inclusive
The maximum possible return of the score function can be obtained by concatenating the first and the third arrays among the given ones, and then calling it.