N,P,Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() ans = 0 for a in range(N): aa = pow(10,A[a],P) for b in range(a+1,N): bb = pow(9,A[b],P) for c in range(b+1,N): cc = pow(7,A[c],P) for d in range(c+1,N): if A[a]