import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val k = nextInt() val c = IntArray(9) { nextInt() } var ans = 0L val pow10 = IntArray(n) { 1 } for (i in 0 until n - 1) { pow10[i + 1] = pow10[i] * 10 % k } fun dfs(r: Int, step: Int, c1: Int, c2: Int, c3: Int, c4: Int, c5: Int, c6: Int, c7: Int, c8: Int, c9: Int) { if (step == n) { if (r == 0) ans++ } else { if (c1 > 0) { val r2 = (r + pow10[step] * 1) % k dfs(r2, step + 1, c1 - 1, c2, c3, c4, c5, c6, c7, c8, c9) } if (c2 > 0) { val r2 = (r + pow10[step] * 2) % k dfs(r2, step + 1, c1, c2 - 1, c3, c4, c5, c6, c7, c8, c9) } if (c3 > 0) { val r2 = (r + pow10[step] * 3) % k dfs(r2, step + 1, c1, c2, c3 - 1, c4, c5, c6, c7, c8, c9) } if (c4 > 0) { val r2 = (r + pow10[step] * 4) % k dfs(r2, step + 1, c1, c2, c3, c4 - 1, c5, c6, c7, c8, c9) } if (c5 > 0) { val r2 = (r + pow10[step] * 5) % k dfs(r2, step + 1, c1, c2, c3, c4, c5 - 1, c6, c7, c8, c9) } if (c6 > 0) { val r2 = (r + pow10[step] * 6) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6 - 1, c7, c8, c9) } if (c7 > 0) { val r2 = (r + pow10[step] * 7) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6, c7 - 1, c8, c9) } if (c8 > 0) { val r2 = (r + pow10[step] * 8) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6, c7, c8 - 1, c9) } if (c9 > 0) { val r2 = (r + pow10[step] * 9) % k dfs(r2, step + 1, c1, c2, c3, c4, c5, c6, c7, c8, c9 - 1) } } } dfs(0, 0, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8]) println(ans) } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion