#include <bits/stdc++.h>
using namespace std;
long long a[300010];
map<long long, int> b, c;
int main() {
  int n, p, k, i, j;
  long long ans = 0;
  scanf("%d%d%d", &n, &p, &k);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    long long t = 1ll * a[i] * a[i] % p;
    b[(t * t % p - 1ll * k * a[i] % p + p) % p]++;
  }
  for (i = 1; i <= n; i++) {
    long long t = 1ll * a[i] * a[i] % p,
              m = (t * t % p - 1ll * k * a[i] % p + p) % p;
    if (!c[m]) ans += 1ll * b[m] * (b[m] - 1);
    c[m] = 1;
  }
  cout << ans / 2;
}
