N,P,Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() ten = [] nine = [] seven = [] five = [] for i in A: ten.append(pow(10,i,P)) nine.append(pow(9,i,P)) seven.append((pow(7,i,P))) five.append((pow(5,i,P))) cnt = 0 #print(ten) #print(nine) #print(seven) #print(five) for a in range(N): for b in range(a+1,N): for c in range(b+1,N): for d in range(c+1,N): #print(a,b,c,d) if (ten[a]+nine[b]+seven[c]+five[d])%P == Q: cnt += 1 print(cnt)