#include using namespace std; using ll = long long; using ld = long double; #ifdef LOCAL #include #else #define debug(...) void(0) #endif #include using namespace atcoder; ll modpow(ll a, ll b, ll m) { ll ret = 1; while(b) { if(b & 1) (ret *= a) % m; (a *= a) % m; b >>= 1; } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll 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()); ll ans = 0; for(int i = 0; i < N; i++) { for(int j = i + 1; j < N; j++) { for(int k = j + 1; k < N; k++) { for(int l = k + 1; l < N; l++) { ll t = modpow(10, A[i], P) + modpow(9, A[j], P) + modpow(7, A[k], P) + modpow(5, A[l], P); t %= P; if(t == Q) ans++; } } } } cout << ans << endl; }