#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
int main() {
  long long n, p, k, a, b, ans = 0;
  scanf("%lld%lld%lld", &n, &p, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a);
    b = (a * a) % p;
    b = (b * b) % p;
    a = (b - a * k) % p;
    if (a < 0) a += p;
    ans += m[a];
    m[a]++;
  }
  printf("%lld", ans);
}
