You are given a prime number p, n integers a1,a2,…,an, and an integer k.
Find the number of pairs of indexes (i,j) (1≤i<j≤n) for which (ai+aj)(ai^ 2 + aj^ 2)≡k mod p.
Input
The first line contains integers n,p,k (2≤n≤3⋅10^ 5, 2≤p≤10^9, 0≤k≤p−1). pp is guaranteed to be prime.
The second line contains nn integers a1,a2,…,an (0≤ai≤p−10≤ai≤p−1). It is guaranteed that all elements are different.
Output
Output a single integer — answer to the problem.
Examples
input
3 3 0
0 1 2
output
1
input
6 7 2
1 2 3 4 5 6
output
3
Note
In the first example:
(0+1)(0^2 + 1 ^2)=3≡1mod3.
(0+2)(0^2 + 2 ^2)=8≡2mod3.
(1+2)(1^2 + 2 ^2)=15≡0mod3.
So only 1 pair satisfies the condition.
In the second example, there are 3 such pairs: (1,5), (2,3), (4,6).
思路:原式:(x+y)(x^ 2 + y^2)%p=k%p,将等式两边同时乘以(x-y)就行,得到:x ^ 4%p-kx%p=y ^ 4%p-ky%p;
因为x^4%p-k*x%p可能小于0;所以要在加个p,具体看代码: