#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int mod = 998244353;
void reduce(int &a) { a += a >> 31 & mod; }
int Mod(int x) { return x >= mod ? x - mod : x; }
long long read() {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const int N = 300010;
int n, k, ans;
unordered_map<int, int> mp;
int main() {
  n = read(), mod = read(), k = read();
  for (int i = 1; i <= n; i++) {
    int a = read();
    int tmp =
        ((long long)a * a % mod * a % mod * a % mod - (long long)k * a % mod);
    reduce(tmp), ans += mp[tmp], mp[tmp]++;
  }
  print(ans), putchar('\n');
}
