#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; const ll INF=9e18; ll ruijo(ll kazu, ll jo, ll P){ bitset<24>bit(jo); ll goukei=1; ll ima=kazu; for (ll a = 0; a < 24; a++){ if(bit.test(a)){ goukei*=ima; goukei%=P; } ima*=ima; ima%=P; } return goukei; } int main() { ll N,P,Q; cin>>N>>P>>Q; vector A (N); for (ll a = 0; a < N; a++){ cin>>A[a]; } sort(A.begin(),A.end()); vector ten (N); vector nine (N); vector seven (N); vector five (N); for (ll a = 0; a < N; a++){ ten[a]=ruijo(10,A[a],P); } for (ll a = 0; a < N; a++){ nine[a]=ruijo(9,A[a],P); } for (ll a = 0; a < N; a++){ seven[a]=ruijo(7,A[a],P); } for (ll a = 0; a < N; a++){ five[a]=ruijo(5,A[a],P); } ll kotae=0; for (ll a = 0; a < N-3; a++){ for (ll b = a+1; b < N-2; b++){ for (ll c = b+1; c < N-1; c++){ for (ll d = c+1; d < N; d++){ //cout<