N,P,Q=map(int, input().split()) A=list(map(int, input().split())) A=sorted(A) ans=0 D,E={},{} for i in range(N-1): for j in range(i+1,N): a=pow(10,A[i],P) b=pow(9,A[j],P) ab=(a+b)%P c=pow(7,A[i],P) d=pow(5,A[j],P) cd=(c+d)%P if ab not in D: D[ab]=[] D[ab].append(j) if cd not in E: E[cd]=[] E[cd].append(i) for e in E: E[e]=sorted(E[e]) import bisect for d in D: q=Q-d if q in E: for now in D[d]: c=bisect.bisect_right(E[q],now) ans+=len(E[q])-c q=2*Q-d if q in E: for now in D[d]: c=bisect.bisect_right(E[q],now) ans+=len(E[q])-c print(ans)