#include using namespace std; using ll=long long; using ld=long double; template using graph=vector>; template using min_priority_queue=priority_queue,greater>; constexpr int INF32=INT_MAX/2; constexpr ll INF64=1LL<<60; constexpr array DX4={0,1,0,-1}; constexpr array DY4={-1,0,1,0}; constexpr array DX8={0,1,1,1,0,-1,-1,-1}; constexpr array DY8={-1,-1,0,1,1,1,0,-1}; inline int popcnt(ll n){return __builtin_popcountll(n);} template inline bool chmax(T& a,const T& b){return a inline bool chmin(T& a,const T& b){return b=(ll)(n);i--) void _main(); int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout< using atcoder::modint; void _main(){ int N, P, Q; cin >> N >> P >> Q; vector A(N); rep(i,0,N) cin >> A[i]; sort(A.begin(), A.end()); modint::set_mod(P); vector pow10(N), pow9(N), pow7(N), pow5(N); rep(i,0,N){ pow10[i] = modint(10).pow(A[i]); pow9[i] = modint(9).pow(A[i]); pow7[i] = modint(7).pow(A[i]); pow5[i] = modint(5).pow(A[i]); } modint q = modint(Q); int ans = 0; rep(i,0,N) rep(j,i+1,N) rep(k,j+1,N) rep(l,k+1,N){ modint a = pow10[i], b = pow9[j], c = pow7[k], d = pow5[l]; if(a+b+c+d==q) ans++; } cout << ans << endl; }