#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 10;
int n, p, a[N], b[N], k;
map<int, int> mp;
long long ans = 0;
int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int main() {
  scanf("%d %d %d", &n, &p, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = add(1ll * a[i] * a[i] % p * a[i] % p * a[i] % p,
               p - 1ll * a[i] % p * k % p);
    mp[b[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    ans += mp[b[i]] - 1;
  }
  ans /= 2;
  printf("%I64d\n", ans);
  return 0;
}
