from collections import defaultdict n, k = map(int, input().split()) c = list(map(int, input().split())) if k == 0: print(0) exit() pow10 = [pow(10, (n - 1 - m), k) for m in range(n)] # Initialize DP with initial state: all counts 0, remainder 0 dp = defaultdict(int) initial_counts = tuple([0] * 9) dp[(initial_counts, 0)] = 1 for m in range(n): next_dp = defaultdict(int) for (counts, rem), cnt in dp.items(): for d in range(9): if counts[d] < c[d]: new_counts = list(counts) new_counts[d] += 1 new_counts_tuple = tuple(new_counts) contribution = (d + 1) * pow10[m] new_rem = (rem + contribution) % k next_dp[(new_counts_tuple, new_rem)] += cnt dp = next_dp # Sum all states where remainder is 0 result = 0 for (counts, rem), cnt in dp.items(): if rem == 0: result += cnt print(result)