#include <bits/stdc++.h>
using namespace std;
map<int, int> Fr;
long long A[(int)(3e5 + 4)], n, p, k, ans, x;
int main() {
  cin >> n >> p >> k;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    A[i] %= p;
    x = (A[i] * A[i]) % p;
    x = (x * x) % p;
    A[i] = (x + p - (k * A[i]) % p) % p;
    ans += Fr[A[i]];
    ++Fr[A[i]];
  }
  cout << ans;
  return 0;
}
