#include using namespace std; #define all(v) (v).begin(),(v).end() #define pb(a) push_back(a) #define rep(i, n) for(int i=0;i 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, p, q; cin >> n >> p >> q; vector a(n); rep(i, n) cin >> a[i]; sort(all(a)); vector> dp(5, vector (p, 0)); ll N = 3000000; vector pow10(N, 1); vector pow9(N, 1); vector pow7(N, 1); vector pow5(N, 1); rep(i, N - 1) pow10[i + 1] = pow10[i] * 10 % p; rep(i, N - 1) pow9[i + 1] = pow9[i] * 9 % p; rep(i, N - 1) pow7[i + 1] = pow7[i] * 7 % p; rep(i, N - 1) pow5[i + 1] = pow5[i] * 5 % p; dp[0][0] = 1; foa(e, a) { vector> nx = dp; for(int i = 0; i < p; i ++) { nx[1][(i + pow10[e]) % p] += dp[0][i]; nx[2][(i + pow9[e]) % p] += dp[1][i]; nx[3][(i + pow7[e]) % p] += dp[2][i]; nx[4][(i + pow5[e]) % p] += dp[3][i]; } swap(nx, dp); } cout << dp[4][q] << endl; return 0; }