using System.Collections.Generic; using System.Numerics; 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 void getAns(int n, int p, int q, int[] a) { var xx = (long)BigInteger.ModPow(7, 128, 17); Array.Sort(a); var d10 = new Dictionary(); var d9 = new Dictionary(); var d7 = new Dictionary(); var d5 = new Dictionary(); foreach (var x in a) { d10[x] = (long)BigInteger.ModPow(10, x, p); d9[x] = (long)BigInteger.ModPow(9, x, p); d7[x] = (long)BigInteger.ModPow(7, x, p); d5[x] = (long)BigInteger.ModPow(5, x, p); } 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 w = d10[a[i]]; w += d9[a[j]]; w %= p; w += d7[a[k]]; w %= p; w += d5[a[L]]; w %= p; if (w == q) c++; } } } } Console.WriteLine(c); } }