#include <bits/stdc++.h>
using namespace std;
map<unsigned long long, unsigned long long> mp;
int n, p, k;
unsigned long long ans, x, y;
int main() {
  scanf("%d %d %d", &n, &p, &k);
  while (n--) {
    scanf("%llu", &x);
    y = x * x % p;
    ans += mp[(y * y % p - k * x % p + p) % p]++;
  }
  printf("%llu", ans);
}
