N, P, Q = map(int, input().split()) A = list(map(int, input().split())) dp = [[[0] * P for i in range(5)] for j in range(N + 1)] dp[0][0][0] = 1 for i in range(1, N + 1): a = pow(10, A[i - 1], P) b = pow(9, A[i - 1], P) c = pow(7, A[i - 1], P) d = pow(5, A[i - 1], P) for j in range(P): dp[i][0][j] += dp[i - 1][0][j] dp[i][1][(j + a) % P] += dp[i - 1][0][j] dp[i][1][j] += dp[i - 1][1][j] dp[i][2][(j + b) % P] += dp[i - 1][1][j] dp[i][2][j] += dp[i - 1][2][j] dp[i][3][(j + c) % P] += dp[i - 1][2][j] dp[i][3][j] += dp[i - 1][3][j] dp[i][4][(j + d) % P] += dp[i - 1][3][j] dp[i][4][j] += dp[i - 1][4][j] print(dp[-1][-1][Q])