#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; //B(n,V(n)) int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,p,q; cin>>n>>p>>q; V A(n); rep(i,n) cin>>A[i]; sort(ALL(A)); VV B(4,V(2002002)); rep(i,4) B[i][0]=1; rep(j,2002000) B[0][j+1]=B[0][j]*10%p; rep(j,2002000) B[1][j+1]=B[1][j]*9%p; rep(j,2002000) B[2][j+1]=B[2][j]*7%p; rep(j,2002000) B[3][j+1]=B[3][j]*5%p; VV C(n+1,V(2002002)); for(int i=n-1;i>=0;i--){ for(int j=0;j<2002002;j++){ C[i][j]=C[i+1][j]; } C[i][B[3][A[i]]]++; } ll ans=0; for(int a=0;a