#include #include #include using namespace std; long long pow(long long x, long long n, long long P) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % P; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % P; n >>= 1; // n を1bit 左にずらす } return ret; } int main() { int N, P, Q; cin >> N >> P >> Q; vector A(N); for (long long &a : A) cin >> a; vector>> dp(N + 1, vector>(5, vector(P, 0))); dp[0][0][0] = 1; for (int i = 1; i <= N; ++i) { int a = pow(10, A[i - 1], P); int b = pow(9, A[i - 1], P); int c = pow(7, A[i - 1], P); int d = pow(5, A[i - 1], P); for (long long j = 0; j < P; ++j) { dp[i][0][j] += dp[i - 1][0][j]; dp[i][1][(j + a) % P] += dp[i - 1][0][j]; dp[i][1][j] += dp[i - 1][1][j]; dp[i][2][(j + b) % P] += dp[i - 1][1][j]; dp[i][2][j] += dp[i - 1][2][j]; dp[i][3][(j + c) % P] += dp[i - 1][2][j]; dp[i][3][j] += dp[i - 1][3][j]; dp[i][4][(j + d) % P] += dp[i - 1][3][j]; dp[i][4][j] += dp[i - 1][4][j]; } } cout << dp[N][4][Q] << endl; return 0; }