N, P, Q = map(int, input().split()) A = list(map(int, input().split())) # 10, 9, 7, 5 # a < b < c < d A.sort() limit = 2*10**6 power10, power9, power7, power5 = [1], [1], [1], [1] for i in range(limit): power10.append(power10[-1] * 10 % P) power9.append(power9[-1] * 9 % P) power7.append(power7[-1] * 7 % P) power5.append(power5[-1] * 5 % P) ans = 0 for i in range(N): a = A[i] for j in range(i + 1, N): b = A[j] if b == a: continue for k in range(j + 1, N): c = A[k] if c == b: continue for l in range(k + 1, N): d = A[l] if d == c: continue if (power10[a] + power9[b] + power7[c] + power5[d]) % P == Q: ans += 1 print(ans)