Are you sad ? Don't be, unlike me
You are given a sad array A of size N and an additional sad integer K. Now, we create a new sad array B, of size N⋅K, where B[i]=A[i], for 0≤i≤N−1 and B[i]=B[i−N] for N≤i≤(N⋅K)−1.
Now, we define an inversion to be a pair of indices (E1,E2) lying in the same subsequence S, such that E1<E2, but B[E1]>B[E2]
Now, you need to cut this sad array B into any number of sad non-empty non-intersecting subsequences. Each element from the given array should belong to exactly one of the subsequences. Let the array be cut into the set of subsequences {S0,S1,...Sk−1}. Let Z be the sum of the number of inversions in each individual subsequence.
You know what's next right? Considering the array can be cut into each distinct set of subsequences with equal probability, you need to find the Expected Value of Z. What this means is that let the array be cut into the set of subsequences {S0,S1..Sk−1} or into subsequences {C0,C1..Cl−1}, where S≠C. The probability of array being in state S or in state C is equal to the probability of the array being cut into any other set of subsequences.
Let the answer be an irreducible fraction P/Q. You need to print P⋅Q−1 Modulo a given prime number M. It is guaranteed, that for all of the given tests, Q≢0 Modulo M. So, the answer will always exist and is unique for the given test-set, since M is prime.
Input Format:
The first line contains 3 space separated integers N, K and M. The next line contains N space-separated integers, where the ith integer denotes A[i].
Output Format:
Print the given answer on a single line
Constraints :
1≤N≤2000
1≤A[i]≤109
1≤K≤1010
3≤M≤5⋅104
M is a prime number
The array can be in any of the following final states, each with equal probability :
{(3),(2),(1)}
{(32),(1)}
{(3,1),(2)}
{(3),(2,1)}
{(3,2,1)}
So, E(Z)=15⋅(0+1+1+1+3)=65=40 Modulo 97