import std; void main () { int N, P, Q; readln.read(N, P, Q); auto A = readln.split.to!(int[]); solve(N, P, Q, A); } void solve (int N, int P, int Q, int[] A) { A.sort; auto dp = new long[][][](N + 1, 5, P); // dp[i][j][k] := 先頭i個からj個とってあまりがk dp[0][0][0] = 1; const x = [10, 9, 7, 5]; foreach (i; 0..N) { foreach (j; 0..5) { foreach (k; 0..P) { // 取る if (j + 1 <= 4) { dp[i + 1][j + 1][(k + mod_pow(x[j], A[i], P)) % P] += dp[i][j][k]; } // 取らない dp[i + 1][j][k] += dp[i][j][k]; } } } writeln(dp[N][4][Q]); } void read (T...) (string S, ref T args) { import std.conv : to; import std.array : split; auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } } long mod_pow (long a, long x, const long MOD) in { assert(0 <= x, "x must satisfy 0 <= x"); assert(1 <= MOD, "MOD must satisfy 1 <= MOD"); assert(MOD <= int.max, "MOD must satisfy MOD*MOD <= long.max"); } do { // normalize a %= MOD; a += MOD; a %= MOD; long res = 1L; long base = a; while (0 < x) { if (0 < (x&1)) (res *= base) %= MOD; (base *= base) %= MOD; x >>= 1; } return res % MOD; }