#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int a[1000001];
map<int, int> mp;
int f(int x) {
  return (1ll * x * x % p * x % p * x % p - 1ll * k * x % p + p) % p;
}
vector<int> v;
int main() {
  scanf("%d%d%d", &n, &p, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mp[f(a[i])]++;
    v.push_back(f(a[i]));
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  long long ans = 0;
  for (int i = 0; i < v.size(); i++) {
    int tmp = mp[v[i]];
    ans += tmp * (tmp - 1) / 2 % 100000007;
    ans %= 100000007;
  }
  printf("%lld", ans);
  return 0;
}
