import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict INF = float("inf") def getlist(): return list(map(int, input().split())) class SegmentTree(object): def __init__(self, N): self.N = N self.N0 = 2 ** (N - 1).bit_length() self.initVal = 0 self.data = [self.initVal] * (2 * self.N0) def calc(self, a, b): return a + b def add(self, k, x): k += self.N0 - 1 self.data[k] += x while k > 0: k = (k - 1) // 2 self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2]) def query(self, l, r): L = l + self.N0; R = r + self.N0 + 1 m = self.initVal while L < R: if R & 1: R -= 1 m = self.calc(m, self.data[R - 1]) if L & 1: m = self.calc(m, self.data[L - 1]) L += 1 L >>= 1; R >>= 1 return m def Binary_Search(x, B, D, M): #初期化 left = 0 right = M itr = -INF #二分探索 while left <= right: mid = (left + right) // 2 if B[mid] <= x - D: itr = max(itr, mid) left = mid + 1 else: right = mid - 1 return itr #処理内容 def main(): N, D = getlist() A = [] for i in range(N): a = int(input()) A.append(a) B = list(set(A)) B.sort() compress = defaultdict(int) M = len(B) # 元の座標→0-indexed for i in range(M): compress[B[i]] = i # 前処理 Seg = SegmentTree(N) for i in range(N): itr = compress[A[i]] Seg.add(itr, 1) for i in range(N): itr = Binary_Search(A[i], B, D, M) if itr == -INF: print(0) else: ans = Seg.query(0, itr) print(ans) if __name__ == '__main__': main()