#MMA Contest 018 D N, P, Q = map(int, input().split()) A = list(map(int, input().split())) #事前に冪を求めておく #Aw + Ax + Ay + Az の順に対応させたいので、後はよしなに W = [pow(10, a, P) for a in A] X = [pow( 9, b, P) for b in A] Y = [pow( 7, c, P) for c in A] Z = [pow( 5, d, P) for d in A] #Zを連想配列に変換 c < dとなるdであって、5^d = Zi となる個数 D = dict() for Zi in Z: if Zi not in D: D[Zi] = 0 D[Zi] += 1 ans = 0 for c in range(N): y = Y[c] D[ Z[c] ] -= 1 for b in range(c): x = X[b] for a in range(b): assert a < b < c w = W[a] #w + x + y + z ≡ Q mod P #z = Q - (w + x + y) mod P z = Q - (w + x + y) z %= P if z in D: ans += D[z] print(ans)