N,mod,C=map(int,input().split()) A=list(map(int,input().split())) result=0 if C>0: T={} T[1]=1 x=1 for i in range(N): a=A[i] if a>0: x*=a x%=mod y=C*pow(x,-1,mod) y%=mod if y in T: result+=T[y] if not x in T: T[x]=1 else: T[x]+=1 else: T={} T[1]=1 x=1 print(result) else: p=[1] print(p[1]) pos=-1 result=0 for i in range(N): if A[i]==0: pos=i result+=pos+1 print(result)