#include using namespace std; int main() { int N, P, Q, C = 0; cin >> N >> P >> Q; vector A(N); vector B(4, vector(N)); auto pow = [&](long long x, long long n) { long long ret = 1; while (n) { if (n & 1) ret = ret * x % P; x = x * x % P; n = n >> 1; } return ret; }; for (int i = 0; i < N; i++) { cin >> A.at(i); B.at(0).at(i) = pow(10, A.at(i)); B.at(1).at(i) = pow(9, A.at(i)); B.at(2).at(i) = pow(7, A.at(i)); B.at(3).at(i) = pow(5, A.at(i)); } for (int i = 0; i < N - 3; i++) for (int j = i + 1; j < N - 2; j++) for (int k = j + 1; k < N - 1; k++) for (int l = k + 1; l < N; l++) if ((B.at(0).at(i) + B.at(1).at(j) + B.at(2).at(k) + B.at(3).at(l)) % P == Q) C++; cout << C << endl; }