using System; public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var p = int.Parse(line[1]); var q = int.Parse(line[2]); line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, p, q, a); } static long[,] makeArray(int p) { var x = new int[] { 10, 9, 7, 5 }; var res = new long[4, 2000001]; for (int i = 0; i < 4; i++) res[i, 0] = 1L; for (int i = 1; i <= 2000000; i++) { for (int j = 0; j < 4; j++) { res[j, i] = res[j, i - 1] * x[j]; res[j, i] %= p; } } return res; } static void getAns(int n, int p, int q, int[] a) { var d = makeArray(p); Array.Sort(a); var c = 0; for (int i = 0; i < n - 3; i++) { for (int j = i + 1; j < n - 2; j++) { for (int k = j + 1; k < n - 1; k++) { for (int L = k + 1; L < n; L++) { var ww = (d[0, a[i]] + d[1, a[j]] + d[2, a[k]] + d[3, a[L]]) % p; if (ww == q) c++; } } } } Console.WriteLine(c); } }