You are given two arrays A, B of length N and an integer denoting P which will be used for hashing.
An array C is formed as follows: c_i = (a_i + b_i) mod N. It is given that the length of C will be min(N, P). You can reorder one of the arrays A or B but not both.
You want the array C to be lexicographically smallest.
Your task is to print the hash of the resulting array C.
Note:
Let C be 0-indexed, print the hash = Sum of (c[i]* P^i) mod{10^9+7}.
Input Format for Debugging:
The first line contains an integer, N, denoting the number of elements in A.
The next line contains an integer, P, denoting the base of the hash.
Each line i of the N subsequent lines (where 0 <= i < N) contains an integer describing A[i].
Each line i of the N subsequent lines (where 0<= i < N) contains an integer describing B[i].