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) { Array.Sort(a); var w = 0L; var c = 0; for (int i = 0; i < n - 3; i++) { var w0 = (long)BigInteger.ModPow(10, a[i], p); for (int j = i + 1; j < n - 2; j++) { var w1 = w0 + (long)BigInteger.ModPow(9, a[j], p); w1 %= p; for (int k = j + 1; k < n - 1; k++) { var w2 = w1 + (long)BigInteger.ModPow(7, a[k], p); w2 %= p; for (int L = k + 1; L < n; L++) { var w3 = w2 + (long)BigInteger.ModPow(5, a[L], p); w3 %= p; if (w3 == q) c++; } } } } Console.WriteLine(c); } }