from itertools import combinations N,P,Q=list(map(int,input().split())) A=list(map(int,input().split())) A.sort() M=[[0 for _ in range(4)] for _ in range(N)] for (i,a) in enumerate(A): M[i][0]=pow(10,a,P) M[i][1]=pow(9,a,P) M[i][2]=pow(7,a,P) M[i][3]=pow(5,a,P) ans=0 for l in combinations(list(range(N)),4): x=0 for i in range(4): x+=M[l[i]][i] x%=P if x==Q:ans+=1 print(ans)