n, d = map(lambda s_: int(s_), input().split()) a = tuple(map(lambda s_: int(s_), input().split())) from collections import defaultdict mo = defaultdict(list) for ai in a: q, r = divmod(ai, d) mo[r].append(q) ans = 0 for l in mo.values(): lc = defaultdict(int) rc = defaultdict(int) for e in l: rc[e] += 1 for me in l: rc[me] -= 1 ans += lc[me - 1] * rc[me + 1] lc[me] += 1 print(ans)