# TLEしたので前半2項後半2項で分ける # 数え上げで、前半2項は累積せず、後半2項は累積すればいいか N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() former_count = [[0]*P for i in range(N)] for a in range(N-3): for b in range(a+1, N-2): calc = (pow(10, A[a], P)+pow(9, A[b], P))%P former_count[b][calc] += 1 #print('a', a, 'b', b, 'calc', calc) #for i in range(1, N): # for j in range(P): # former_count[i][j] += former_count[i-1][j] #for f in former_count: # print(f) latter_count = [[0]*P for i in range(N)] for c in range(2, N-1): for d in range(c+1, N): calc = (pow(7, A[c], P)+pow(5, A[d], P))%P latter_count[c][calc] += 1 #print('c', c, 'd', d, 'calc', calc) for i in range(N-2, -1, -1): for j in range(P): latter_count[i][j] += latter_count[i+1][j] #for l in latter_count: # print(l) ans = 0 for b in range(1, N-2): #print(b) for j in range(P): calc = former_count[b][j]*latter_count[b+1][(Q-j)%P] #print('b', b, 'j', j, 'calc', calc) ans += calc print(ans)