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) { // なんかMLEしたのでnextdpやる A.sort; auto dp = new long[][](5, P); auto ndp = new long[][](5, P); // dp[i][j][k] := 先頭i個からj個とってあまりがk dp[0][0] = 1; const x = [10, 9, 7, 5]; auto memo = new long[][](4, N); foreach (i; 0..4) foreach (j; 0..N) memo[i][j] = mod_pow(x[i], A[j], P); foreach (i; 0..N) { foreach (j; 0..5) { foreach (k; 0..P) { // 取る if (j + 1 <= 4) { ndp[j + 1][(k + memo[j][i]) % P] += dp[j][k]; } // 取らない ndp[j][k] += dp[j][k]; } } swap(dp, ndp); } writeln(dp[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; }