n,c = map(int,input().split())
lst = list(map(int,input().split()))
lst.sort(reverse=True)
count = 0
p1 = 0
p2 = 1
while True:
a = lst[p1]
b = lst[p2]
num = a-b
if num<c:
p2+=1
elif num>c:
p1+=1
else:
count+=1
if lst[p1]==lst[p1+1]:
count+=1
p1+=1
if lst[p2] == lst[p2 + 1]:
count += 1
p2+=1
elif lst[p2]==lst[p2+1]:
count+=1
p2+=1
if p2>=n-1:
break
print(count)