from itertools import combinations N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() m = max(A) + 1 m10 = [1] * m m9 = [1] * m m7 = [1] * m m5 = [1] * m for i in range(1, m): m10[i] = m10[i-1] * 10 % P m9[i] = m9[i-1] * 9 % P m7[i] = m7[i-1] * 7 % P m5[i] = m5[i-1] * 5 % P ans = 0 na = len(A) for a in range(na): for b in range(a+1, na): for c in range(b+1, na): for d in range(c+1, na): x = m10[A[a]] + m9[A[b]] + m7[A[c]] + m5[A[d]] if x % P == Q: ans += 1 # for a, b, c, d in combinations(A, 4): # x = m10[a] + m9[b] + m7[c] + m5[d] # if x % P == Q: # ans += 1 print(ans)