using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k) = (c[0], c[1]); c = NList; var num = new List(); var clist = new List(); var dlist = new List(); var bitmax = 1; for (var i = 0; i < 9; ++i) if (c[i] > 0) { num.Add(i + 1); clist.Add(c[i]); if (dlist.Count == 0) dlist.Add(1); else dlist.Add(dlist[^1] * (clist[^2] + 1)); bitmax *= c[i] + 1; } var dp = new long[bitmax][]; for (var i = 0; i < dp.Length; ++i) dp[i] = new long[k]; dp[0][0] = 1; for (var b = 0; b < bitmax; ++b) { for (var i = 0; i < clist.Count; ++i) { var ci = b / dlist[i] % (clist[i] + 1); if (ci == clist[i]) continue; for (var j = 0; j < k; ++j) { var next = (j * 10 + num[i]) % k; dp[b + dlist[i]][next] += dp[b][j]; } } } WriteLine(dp[^1][0]); } }