import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto s = readln.split; auto N = s[0].to!int; auto K = s[1].to!int; auto A = 0 ~ readln.split.map!(to!int).array; int[] B; foreach (i; 1..10) foreach (_; 0..A[i]) B ~= i; int[] base = new int[](N+1); base[0] = 1; foreach (i; 1..N+1) base[i] = base[i-1] * 10 % K; auto dp = new long[][](1< 0 && B[i] == B[i-1] && !(mask & (1 << (i-1)))) continue; int keta = mask.popcnt; int num = base[keta] * B[i] % K + j; num %= K; dp[(mask | (1 << i))][num] += dp[mask][j]; } } dp[(1<