#include <bits/stdc++.h>
using namespace std;
void read(int &val) {
  int x = 0;
  int bz = 1;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    bz = -1;
    c = getchar();
  }
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  val = x * bz;
}
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, m, a[maxn];
unordered_map<long long, long long> mp;
int main() {
  int k;
  read(n);
  read(m);
  read(k);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= n; i++) {
    long long res = 1LL * a[i] * a[i] % m * a[i] % m * a[i] % m;
    res = (res - 1LL * k * a[i] % m) % m + m;
    res %= m;
    mp[res]++;
  }
  long long ans = 0;
  for (auto to : mp) {
    long long num = to.second;
    if (num <= 1) continue;
    ans += (num * (num - 1)) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
