N, P, Q = map(int, input().split()) A = list(map(int, input().split())) current = [[0] * P for i in range(5)] previous = [[0] * P for i in range(5)] previous[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) # currentをリセット for j in range(5): for k in range(P): current[j][k] = 0 for j in range(P): current[0][j] += previous[0][j] current[1][(j + a) % P] += previous[0][j] current[1][j] += previous[1][j] current[2][(j + b) % P] += previous[1][j] current[2][j] += previous[2][j] current[3][(j + c) % P] += previous[2][j] current[3][j] += previous[3][j] current[4][(j + d) % P] += previous[3][j] current[4][j] += previous[4][j] previous, current = current, previous print(previous[4][Q])