from collections import defaultdict N,P=map(int,input().split()) def solve(A): if len(A)==1: return 0 dct=defaultdict(list) for a in A: dct[a%P].append(a) ans=0 for a,A in dct.items(): le=len(A) ans+=solve([(aa-a)//P for aa in A])+le*(le-1)//2 return ans A=list(map(int,input().split())) ans=solve(A) print(ans)