N, D = map(int, input().split()) A = list(map(int, input().split())) cnt = {} for a in A: base1 = a * 10 + 1 base2 = a * 10 + 2 t1 = (a + D) * 10 + 1 t2 = (a + D) * 10 + 2 t3 = (a + D) * 10 + 3 cnt[t1] = cnt.get(t1, 0) + 1 # A*10+1 がある場合 if base1 in cnt: cnt[t2] = cnt.get(t2, 0) + cnt[base1] # A*10+2 がある場合 if base2 in cnt: cnt[t3] = cnt.get(t3, 0) + cnt[base2] # 下一桁が3の値を合計 ans = 0 for k in cnt: if k % 10 == 3: ans += cnt[k] print(ans)