N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() ans = 0 for i in range(N): for j in range(i+1,N): for m in range(j+1,N): for k in range(m+1,N): total = 10**A[i]+9**A[j]+7**A[m]+5**A[k] if (total)%P == Q: ans += 1 print(ans)