#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n;
long long p, k;
long long a[N], ans, sum;
int main() {
  scanf("%d%lld%lld", &n, &p, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i] = (a[i] * a[i] % p * a[i] % p * a[i] % p - a[i] * k % p + p) % p;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++)
    if ((a[i] == a[i - 1]) && (i != 1)) {
      sum++;
    } else {
      ans += sum * (sum - 1) / 2;
      sum = 1;
    }
  ans += sum * (sum - 1) / 2;
  cout << ans << endl;
}
