#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, p, q; cin >> n >> p >> q; vector dp(5, vector(p)); vector a(n), b = {10, 9, 7, 5}; cin >> a; sort(a.begin(), a.end()); dp[0][0] = 1; for(auto &&v : a){ for(int j = 3; j >= 0; j--){ for(int k = 0; k < p; k++){ if(dp[j][k] == 0) continue; int v2 = modpow(b[j], v, p) + k; if(v2 >= p) v2 -= p; dp[j + 1][v2] += dp[j][k]; } } } cout << dp[4][q] << '\n'; }