from heapq import heappush, heappop, heapify import sys from collections import defaultdict, deque,Counter from math import ceil, floor, sqrt, factorial,gcd from itertools import permutations, combinations,product from bisect import bisect_left, bisect_right from copy import deepcopy from functools import lru_cache #@lru_cache(maxsize=None) from fractions import Fraction sys.setrecursionlimit(10**6) # input = sys.stdin.readline vector1 = [[0, -1], [1, 0], [0, 1], [-1, 0]] vector2 = [[0, 1], [1, 0], [-1, 0], [0, -1], [1,-1], [-1, 1], [1, 1], [-1, -1]] from copy import deepcopy def main(): N,P,Q = map(int,input().split()) A = list(map(int,input().split())) A.sort() array = [[0 for i in range(P)]] for i in range(N): m = pow(5,A[i],P) tmp = deepcopy(array[-1]) tmp[m] += 1 array.append(tmp) ans = 0 d = defaultdict(int) for a in A: if d[a]: continue else: d[a] = 1 d[(a,10)] = pow(10,a,P) d[(a,9)] = pow(9,a,P) d[(a,7)] = pow(7,a,P) for i in range(N-3): for j in range(i+1,N-2): if A[i] == A[j]: continue for k in range(j+1,N-1): if A[j] == A[k]: continue t = (d[(A[i],10)] + d[(A[j],9)] + d[(A[k],7)]) % P t = (Q-t)%P ans += array[-1][t]-array[k+1][t] print(ans) if __name__ == '__main__': main()