n, p, q = map(int, input().split()) a = list(map(int, input().split())) a.sort() ma = a[-1] p10 = [1] * (ma + 1) p9 = [1] * (ma + 1) p7 = [1] * (ma + 1) p5 = [1] * (ma + 1) for i in range(0, ma): p10[i + 1] = p10[i] * 10 % p p9[i + 1] = p9[i] * 9 % p p7[i + 1] = p7[i] * 7 % p p5[i + 1] = p5[i] * 5 % p ans = 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): for l in range(k + 1, n): if (p10[a[i]] + p9[a[j]] + p7[a[k]] + p5[a[l]]) % p == q: ans += 1 print(ans)