using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var x = NList; var (n, p, q) = (x[0], x[1], x[2]); var y = NList; var i10 = new long[n]; var i9 = new long[n]; var i7 = new long[n]; var i5 = new long[n]; for (var i = 0; i < n; ++i) { i10[i] = Exp(10, y[i], p); i9[i] = Exp(9, y[i], p); i7[i] = Exp(7, y[i], p); i5[i] = Exp(5, y[i], p); } var ans = 0; for (var a = 0; a < n; ++a) for (var b = a + 1; b < n; ++b) for (var c = b + 1; c < n; ++c) for (var d = c + 1; d < n; ++d) { if ((i10[a] + i9[b] + i7[c] + i5[d]) % p == q) ++ans; } WriteLine(ans); } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } }