from copy import copy from collections import defaultdict N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() A_10 = [pow(10, a, P) for a in A] A_9 = [pow(9, a, P) for a in A] A_7 = [pow(7, a, P) for a in A] A_5 = [pow(5, a, P) for a in A] A_5_dict_list = [{} for _ in range(N)] di = defaultdict(int) for i in range(N - 1, -1, -1): di[A[i]] += 1 A_5_dict_list[i] = copy(di) ans = 0 for i in range(N - 3): for j in range(i + 1, N - 2): for k in range(j + 1, N - 1): for l in range(k + 1, N): if (A_10[i] + A_9[j] + A_7[k] + A_5[l]) % P == Q: ans += 1 print(ans)