inf = open('che.in', 'r')
ouf = open('che.out', 'w')

n, r = map(int, inf.readline().split())
d = list(map(int, inf.readline().split()))

j = 0
ans = 0
for i in range(n):
	while j < n and d[j] - d[i] <= r:
		j += 1
	ans += n - j


print(ans, file=ouf)
