CF-2095E•Codeforces

Pair Count

*specialnumber theory

You are given a prime number pp, nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, and an integer kk.

Find the number of pairs of indexes (i,j)(i, j) (1≤i<j≤n1 \le i \lt j \le n) for which (ai⊕aj)(ai2⊕aj2)≡k mod p(a_i \oplus a_j)(a_i^2 \oplus a_j^2) \equiv k \bmod p.

Here ⊕\oplus denotes the bitwise XOR operation.

Input

The first line contains integers n,p,kn, p, k (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5, 2≤p≤1092 \le p \le 10^9, 0≤k≤p−10 \le k \le p-1). pp is guaranteed to be prime.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤p−10 \le a_i \le p-1). It is guaranteed that all elements are different.

Output

Output a single integer — answer to the problem.

Note

In the first example:

(0⊕1)(02⊕12)=1≡1 mod 3(0\oplus1)(0^2 \oplus 1^2) = 1 \equiv 1 \bmod 3.

(0⊕2)(02⊕22)=8≡2 mod 3(0\oplus2)(0^2 \oplus 2^2) = 8 \equiv 2 \bmod 3.

(1⊕2)(12⊕22)=15≡0 mod 3(1\oplus2)(1^2 \oplus 2^2) = 15 \equiv 0 \bmod 3.

So only 11 pair satisfies the condition.

In the second example, there are 33 such pairs: (1,5)(1, 5), (1,6)(1, 6), (3,6)(3, 6).

Sample 1
Input
3 3 2
0 1 2
Output
1
Sample 2
Input
6 11 2
1 3 5 6 7 8
Output
3

Discussions & Comments

Share your approach or ask questions about this problem (0)

You must be logged in to comment or start a discussion on this problem.

Log In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments