#include <bits/stdc++.h>
using namespace std;
inline int readInt() {
  int N = 0;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) N = (N << 3) + (N << 1) + c - '0';
  return N;
}
int n;
long long p, k;
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> p >> k;
  k %= p;
  long long tot = 0LL;
  for (long long i = 1, a; i <= n; i++) {
    cin >> a;
    a %= p;
    long long a2 = a * a;
    a2 %= p;
    long long cur = (a2 * a2 % p) + p - (1LL * a * k) % p;
    cur %= p;
    if (cur < 0) cur += p;
    tot += mp[cur];
    mp[cur]++;
  }
  cout << tot << '\n';
  return 0;
}
