#include <bits/stdc++.h>
using namespace std;
long long int arr[333333], arr2[333333];
map<long long int, vector<int> > m;
map<long long int, int> vis;
int main(void) {
  long long int n, p, k;
  scanf("%lld%lld%lld", &n, &p, &k);
  for (int e = 0; e < n; e++) scanf("%lld", &arr[e]);
  for (int e = 0; e < n; e++) {
    long long int now = arr[e];
    for (int q = 0; q < 3; q++) now = (now * arr[e]) % p;
    long long int kk = (k * arr[e]) % p;
    arr2[e] = (now - kk + p) % p;
  }
  sort(arr2, arr2 + n);
  long long int ans = 0;
  long long int tot = 1;
  for (int e = 1; e < n; e++) {
    if (arr2[e] == arr2[e - 1]) {
      tot++;
    } else {
      ans += ((tot * (tot - 1)) / 2);
      tot = 1;
    }
  }
  ans += ((tot * (tot - 1)) / 2);
  printf("%lld", ans);
}
