from collections import defaultdict as dd import bisect def pow(x, n, mod): ans = 1 #n が 0 になるまで計算を続ける while n: if n % 2: ans *= x ans %= mod x *= x n >>= 1 return ans%mod N,P,Q = map(int, input().split()) A = list(map(int, input().split())) A = list(set(A)) A.sort() N = len(A) A_div = [ [0 for i in range(4)] for _ in range(N)] num = [10,9,7,5] for i in range(N): for j in range(4): A_div[i][j] = pow(num[j], A[i], P) ans = 0 for i in range(N-3): for j in range(i, N-2): if i==j or A[i]>=A[j]: continue for k in range(j, N-1): if j==k or A[j]>=A[k]: continue for l in range(k, N): if l==k or A[k]>=A[l]: continue if A[i]