#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long int a[300005];
int main() {
  long long int n, p, k, i, j;
  while (cin >> n >> p >> k) {
    for (long long int i = 1; i < n + 1; i++) cin >> a[i];
    map<long long int, long long int> mp;
    long long int ans = 0;
    for (i = 1; i <= n; i++) {
      long long int r = (a[i] * a[i]) % p;
      r = (r * r) % p;
      long long int r1 = (k * a[i]) % p;
      long long int r2 = (r - r1 + p) % p;
      ans += mp[r2];
      mp[r2]++;
    }
    cout << ans << endl;
  }
  return 0;
}
