# 200の4乗は不可能だが、200の3乗ならできる、最後だけ事前カウントしておくのはどうだろう # これでダメなら先頭2項のmod、後半2項のmodで可能かも N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() #print(A) last_count = [[0]*P for i in range(N)] for i in range(N-1, -1, -1): if i == N-1: calc = pow(5, A[i], P) last_count[i][calc] += 1 else: for j in range(P): last_count[i][j] = last_count[i+1][j] calc = pow(5, A[i], P) last_count[i][calc] += 1 #print('i', i, 'calc', calc) #for l in last_count: # print(l) # Ai!=Ajなのでダブりは考えなくていい ans = 0 for a in range(N-3): for b in range(a+1, N-2): for c in range(b+1, N-1): calc = pow(10, A[a], P)+pow(9, A[b], P)+pow(7, A[c], P) needed = (Q-calc)%P #print(a, b, c, 'needed', needed) count = last_count[c+1][needed] ans += count print(ans)