N,P,Q = map(int,input().split()) A = list(map(int,input().split())) R,S,T,U = [],[],[],[] for a in A: R.append(pow(10,a,P)) S.append(pow(9,a,P)) T.append(pow(7,a,P)) U.append(pow(5,a,P)) cnt = 0 for i in range(0,N-3): a = R[i] for j in range(i+1,N-2): b = S[j] for k in range(j+1,N-1): c = T[k] for l in range(k+1, N): d = U[l] if (a+b+c+d)%P == Q: cnt += 1 print(cnt)