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, a: IntArray) { if (step == n) { if (r == 0) ans++ } else { for (i in 0 until 9) { if (a[i] > 0) { val r2 = (r + pow10[step] * (i + 1)) % k val a2 = a.copyOf() a2[i]-- dfs(r2, step + 1, a2) } } } } dfs(0, 0, c) 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