#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; ll pow_mod(ll x, ll n, ll mod) { ll ret = 1; while (n > 0) { if (n & 1) { ret = ret * x % mod; } x = x * x % mod; n >>= 1; } return ret; } const vector E = {10, 9, 7, 5}; int main() { int N, P, Q; cin >> N >> P >> Q; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); vector> B(N, vector(4)); for (int i = 0; i < N; i++) { for (int j = 0; j < 4; j++) { B[i][j] = pow_mod(E[j], A[i], P); } } vector>> dp(2, vector>(P, vector(5, 0))); dp[0][0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < P; j++) { for (int k = 0; k < 5; k++) { dp[1 - i % 2][j][k] += dp[i % 2][j][k]; if (k == 4) { continue; } dp[1 - i % 2][(j + B[i][k]) % P][k + 1] += dp[i % 2][j][k]; } } for (int j = 0; j < P; j++) { for (int k = 0; k < 5; k++) { dp[i % 2][j][k] = 0; } } } cout << dp[N % 2][Q][4] << endl; }