N, P, Q = map(int, input().split(" ")) A = sorted(list(map(int, input().split(" ")))) def mod_pow(a, n, mod): res = 1 while n > 0: if n & 1: res = res * a % mod a = a * a % mod n >>= 1 return res # dp[i:0-4][Aj以下の数だけを使った時][あまりがkになるパターン数] dp = [[[0 for _ in range(P)] for _ in range(N)] for _ in range(4)] for i, x in enumerate([10, 9, 7, 5]): if i == 0: for j in range(N): dp[i][j][mod_pow(x, A[j], P)] = 1 else: for j in range(i, N): aj_pow = mod_pow(x, A[j], P) for k in range(P): idx = (k + aj_pow) % P dp[i][j][idx] = (dp[i][j][idx] + dp[i-1][j-1][k]) % P for j in range(1, N): for k in range(P): dp[i][j][k] = (dp[i][j][k] + dp[i][j-1][k]) % P ans = 0 for j in range(N): ans += dp[i][j][Q] print(ans)