n,p,q=map(int,input().split()) a=list(map(int,input().split())) mx=2000008 p10=[0]*mx p09=[0]*mx p07=[0]*mx p05=[0]*mx p10[0]=1 p09[0]=1 p07[0]=1 p05[0]=1 for i in range(1,mx): p10[i]=p10[i-1]*10%p p09[i]=p09[i-1]* 9%p p07[i]=p07[i-1]* 7%p p05[i]=p05[i-1]* 5%p from collections import defaultdict d=defaultdict(int) ans=0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): g=(p09[a[i]]+p07[a[j]]+p05[a[k]])%p #g+?=q #g+?=p+q ans+=d[p+q-g]+d[q-g] d[p10[a[i]]]+=1 print(ans)