import sys from collections import defaultdict def main(): N, K = map(int, sys.stdin.readline().split()) c = list(map(int, sys.stdin.readline().split())) counts = tuple(c) dp = defaultdict(int) dp[(counts, 0)] = 1 # Initial state: all counts available, remainder 0 for _ in range(N): next_dp = defaultdict(int) for (current_counts, rem), cnt in dp.items(): for d in range(1, 10): idx = d - 1 if current_counts[idx] == 0: continue new_counts = list(current_counts) new_counts[idx] -= 1 new_counts_tuple = tuple(new_counts) new_rem = (rem * 10 + d) % K next_dp[(new_counts_tuple, new_rem)] += cnt dp = next_dp # Update to next step's states # After N steps, check for all digits used and remainder 0 final_counts = tuple([0] * 9) print(dp.get((final_counts, 0), 0)) if __name__ == "__main__": main()