#include #include using namespace std; using Int = atcoder::modint; ostream& operator<<(ostream &os, const Int &x) { return os << x.val(); } int main() { int N, P, Q; cin >> N >> P >> Q; vector A(N); for (int i=0; i < N; ++i) cin >> A[i]; Int::set_mod(P); sort(A.begin(), A.end()); auto R = vector(N, array{}); for (int i=0; i < N; ++i) { R[i][0] = Int(10).pow(A[i]); R[i][1] = Int(9).pow(A[i]); R[i][2] = Int(7).pow(A[i]); R[i][3] = Int(5).pow(A[i]); } long long cnt{}; for (int ai=0; ai < N; ++ai) for (int bi=ai+1; bi < N; ++bi) for (int ci=bi+1; ci < N; ++ci) for (int di=ci+1; di < N; ++di) cnt += R[ai][0] + R[bi][1] + R[ci][2] + R[di][3] == Q; cout << cnt << endl; }