#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  int n, p, k;
  cin >> n >> p >> k;
  long long ans = 0;
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    int t =
        ((long long)x * x % p * x % p * x % p - (long long)k * x % p + p) % p;
    ans += mp[t];
    mp[t]++;
  }
  cout << ans << endl;
}
