You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line.

Two points $i$ and $j$ can be matched with each other if the following conditions hold:  neither $i$ nor $j$ is matched with any other point;  $|x_i - x_j| \ge z$. 

What is the maximum number of pairs of points you can match with each other?


-----Input-----

The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) — the number of points and the constraint on the distance between matched points, respectively.

The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$).


-----Output-----

Print one integer — the maximum number of pairs of points you can match with each other.


-----Examples-----
Input
4 2
1 3 3 7

Output
2

Input
5 5
10 9 5 8 7

Output
1



-----Note-----

In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$).

In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$).

Difficulty: HARD

Solutions:
(n, z) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = [0] + arr
s_arr = sorted(arr)
f_arr = [1] * (n + 1)
l = 1
r = int((n + 1) / 2) + 1
cnt = 0
while r <= n and l <= r:
	if s_arr[r] - s_arr[l] >= z:
		cnt += 1
		l += 1
	r += 1
print(cnt)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
k = n // 2
s = 0
mas = [0] * n
for i in range(n):
	if mas[i] == 1:
		continue
	for j in range(k, n):
		if a[j] - a[i] >= m and mas[j] != 1:
			mas[i] = 1
			mas[j] = 1
			k = j + 1
			s += 1
			break
		if j == n - 1:
			print(s)
			exit()
print(s)


def find_intervals(points, dist):
	length = len(points)
	used = [False for i in range(length)]
	l_pointer = 0
	r_pointer = length // 2
	intervals = 0
	while l_pointer < length // 2 and r_pointer < length:
		if used[l_pointer]:
			l_pointer += 1
			continue
		if used[r_pointer] or points[r_pointer] < points[l_pointer] + dist:
			r_pointer += 1
			continue
		used[l_pointer] = True
		used[r_pointer] = True
		intervals += 1
	return intervals
(n, dist) = map(int, input().split())
points = list(map(int, input().split()))
print(find_intervals(sorted(points), dist))


(n, z) = map(int, input().split())
arr = sorted(map(int, input().split()))
(i, j, count) = (0, n // 2, 0)
while i < n // 2 and j < n:
	if arr[i] + z <= arr[j]:
		count += 1
		i += 1
	j += 1
print(count)


(n, z) = map(int, input().split(' '))
x = sorted(map(int, input().split(' ')))
(l, r) = (0, n // 2)
res = 0
while l < n // 2 and r < n:
	if x[r] - x[l] >= z:
		res += 1
		l += 1
	r += 1
print(res)


import sys
input = sys.stdin.readline
(n, z) = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()

def match(cut):
	i = 0
	j = cut
	ANS = 0
	for i in range(cut):
		while j < n and X[j] - X[i] < z:
			j += 1
		if j == n:
			break
		else:
			ANS += 1
			j += 1
	return ANS
MIN = 1
MAX = n - 1
while MAX - MIN > 1:
	MID0 = (MIN + MAX) // 2 - 1
	MID1 = (MIN + MAX) // 2
	ANS2 = match(MID0)
	ANS3 = match(MID1)
	if ANS2 == ANS3:
		print(ANS2)
		return
	if ANS2 > ANS3:
		MAX = MID0
	else:
		MIN = MID1
print(max(match(MIN), match(MAX)))


def find(A, z):

	def check(k, z):
		L = A[:k]
		R = A[-k:]
		for i in range(len(L)):
			if abs(L[i] - R[i]) >= z:
				continue
			else:
				return False
		return True
	A = sorted(A)
	left = 0
	right = len(A) // 2
	while right - left > 1:
		mid = (left + right) // 2
		if check(mid, z):
			left = mid
		else:
			right = mid
	if check(left + 1, z):
		return left + 1
	else:
		return left
(n, z) = list(map(int, input().strip().split(' ')))
A = list(map(int, input().strip().split(' ')))
print(find(A, z))


nz = input().split()
n = int(nz[0])
z = int(nz[1])
a = input().split()
res = 0
for i in range(n):
	a[i] = int(a[i])
m = (n + 1) // 2
(f, s) = (0, m)
a = sorted(a)
while f < m and s < n:
	if a[s] - a[f] >= z:
		res += 1
		f += 1
		s += 1
	else:
		s += 1
print(res)


(n, m) = map(int, input().split())
li = [int(k) for k in input().split()]
mark = [0] * n
i = 0
j = n // 2
li.sort()
ans = 0
while i < n and j < n:
	if i != j and li[j] - li[i] >= m and (mark[i] == 0) and (mark[j] == 0):
		ans += 1
		mark[i] = 1
		mark[j] = 1
		i += 1
		j += 1
	elif li[j] - li[i] < m:
		if mark[i] == 1 and mark[j] == 0:
			i += 1
		elif mark[j] == 1 and mark[i] == 0:
			j += 1
		elif mark[j] == 1 and mark[i] == 1:
			i += 1
			j += 1
		elif mark[j] == 0 and mark[i] == 0:
			j += 1
	elif li[j] - li[i] >= m:
		if mark[i] == 1 and mark[j] == 0:
			i += 1
		elif mark[j] == 1 and mark[i] == 0:
			j += 1
		elif mark[j] == 1 and mark[i] == 1:
			i += 1
			j += 1
print(ans)


(n, m) = list(map(int, input().split()))
array = sorted(map(int, input().split()))
(res, i, j) = (0, 0, 0)
while i < n // 2 and j < n:
	if array[i] + m <= array[j]:
		i += 1
		res += 1
	j += 1
print(res)


def solve():
	(n, z) = [int(s) for s in input().split(' ')]
	x = [int(s) for s in input().split(' ')]
	x.sort()

	def good(k):
		if 2 * k > n:
			return False
		for i in range(k):
			if x[-(k - i)] - x[i] < z:
				return False
		return True
	l = 0
	r = n
	while r - l > 1:
		m = (l + r) // 2
		if good(m):
			l = m
		else:
			r = m
	return l
print(solve())


(n, z) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
c = 0
l = 0
r = len(arr) // 2
while r < len(arr) and l < len(arr):
	if arr[l] == -1:
		l += 1
		continue
	if arr[r] - arr[l] >= z and arr[r] != -1:
		arr[r] = -1
		c += 1
		r += 1
		l += 1
	else:
		r += 1
print(c)


def __starting_point():
	(n, z) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	mask = [0 for i in range(n)]
	start = int((n - 1) / 2)
	end = n - 1
	res = 0
	while end >= 0:
		if abs(a[start] - a[end]) >= z and mask[end] == 0 and (mask[start] == 0):
			mask[start] = 1
			mask[end] = 1
			start -= 1
			end -= 1
			res += 1
		elif mask[start] == 1:
			start -= 1
		elif mask[end] == 1:
			end -= 1
		else:
			start -= 1
		if start < 0:
			break
	print(res)
__starting_point()


(N, K) = map(int, input().split())
L = sorted(list(map(int, input().split())))
B = [True for n in range(N)]
P = 0
i = 0
j = N // 2
while i < N and j < N:
	while j < N and L[i] + K > L[j]:
		j += 1
	if i < j < N and B[i] and B[j]:
		B[i] = False
		B[j] = False
		P += 1
	i += 1
	j += 1
print(P)


import math
import collections
read = lambda : map(int, input().split())
(n, z) = read()
a = list(read())
a.sort()
l = 0
r = n // 2 + 1
while r - 1 > l:
	m = (r + l) // 2
	flag = True
	for i in range(m):
		flag &= a[n - m + i] - a[i] >= z
	if flag:
		l = m
	else:
		r = m
print(l)


def solve():
	(N, Z) = map(int, input().split())
	X = [int(k) for k in input().split()]
	X.sort()
	ans = 0
	i = 0
	mid = N // 2 + (1 if N % 2 else 0)
	j = mid
	while i < mid and j < N:
		while j < N and X[j] - X[i] < Z:
			j += 1
		if j != N:
			ans += 1
		i += 1
		j += 1
	print(ans)

def __starting_point():
	solve()
__starting_point()


(N, Z) = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()

def compute(x1, x2):
	count = 0
	i = 0
	j = 0
	while i < len(x1) and j < len(x2):
		while x2[j] - x1[i] < Z:
			j += 1
			if j == len(x2):
				return count
		count += 1
		i += 1
		j += 1
	return count
if N % 2 == 0:
	print(compute(X[0:N // 2], X[N // 2:]))
else:
	v1 = compute(X[0:N // 2], X[N // 2:])
	v2 = compute(X[0:N // 2 + 1], X[N // 2 + 1:])
	print(max(v1, v2))


(n, z) = list(map(int, input().split()))
arrs = [int(x) for x in input().split()]
arrs.sort()

def fi(k):
	l = arrs[:k]
	r = arrs[-k:]
	return all([r[i] - l[i] >= z for i in range(len(r))])
l = 0
r = len(arrs) // 2 + 1
while r - l > 1:
	m = (l + r) // 2
	if fi(m):
		l = m
	else:
		r = m
print(l)


from collections import defaultdict

def nice_team(ratings, min_diff):
	ratings.sort()
	d = defaultdict(int)
	for i in ratings:
		d[i] += 1
	big_idx = len(ratings) // 2
	small_idx = 0
	maximum_pair = 0
	while big_idx < len(ratings) and small_idx < len(ratings):
		if ratings[big_idx] - ratings[small_idx] < min_diff:
			big_idx += 1
		elif d[ratings[big_idx]] > 0 and d[ratings[small_idx]] > 0:
			d[ratings[big_idx]] -= 1
			d[ratings[small_idx]] -= 1
			maximum_pair += 1
			big_idx += 1
			small_idx += 1
		else:
			if d[ratings[big_idx]] == 0:
				big_idx += 1
			if d[ratings[small_idx]] == 0:
				small_idx += 1
				if big_idx == small_idx:
					big_idx += 1
	return maximum_pair
(size, min_diff) = list(map(int, input().split()))
arr = list(map(int, input().split()))
result = nice_team(arr, min_diff)
print(result)


import math
import collections
read = lambda : map(int, input().split())
(n, z) = read()
a = sorted(read())
(res, l, r) = (0, 0, n // 2)
while l < n // 2 and r < n:
	if a[l] + z <= a[r]:
		res += 1
		l += 1
	r += 1
print(res)


(n, z) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
l = 0
h = n // 2 + 1
while h - l > 1:
	m = (h + l) // 2
	flag = True
	for i in range(m):
		if arr[n - m + i] - arr[i] < z:
			flag = False
	if flag:
		l = m
	else:
		h = m
print(l)


(n, z) = map(int, input().split())
lis = sorted(list(map(int, input().split())))
x = n // 2
res = 0
start = x
for i in range(x):
	if start < n:
		while lis[start] - lis[i] < z:
			if start < n - 1:
				start += 1
			else:
				break
		else:
			start += 1
			res += 1
	else:
		break
print(res)


def maxpairs(ls, mdiff):
	cou = 0
	ls.sort()
	id2 = int(len(ls) / 2)
	for i in range(len(ls) // 2):
		flag = True
		cp_i = ls[i]
		while id2 <= len(ls) - 1:
			flag = False
			if cp_i + mdiff <= ls[id2]:
				cou += 1
				id2 += 1
				break
			id2 += 1
		if flag:
			break
	return cou
(a, mdiff) = map(int, input().split())
ls = list(map(int, input().strip().split()))
print(maxpairs(ls, mdiff))


from math import ceil
(n, z) = map(int, str(input()).split())
x = list(map(int, str(input()).split()))
x.sort()
y = [0] * n
i = 0
j = ceil(n / 2)
p = 0
while j < n and i < j:
	if x[j] - x[i] >= z:
		if y[i] + y[j] == 0:
			y[i] = 1
			y[j] = 1
			p += 1
			i += 1
			j += 1
		else:
			if y[i] == 1:
				i += 1
			if y[j] == 1:
				j += 1
	else:
		j += 1
print(p)


def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def solve():
	t = 1
	for _ in range(t):
		(n, z) = num()
		a = li()
		a.sort()
		cc = 0
		l = 0
		end = n // 2
		while l <= end:
			mid = (l + end) // 2
			fl = True
			for i in range(mid):
				if a[n - mid + i] - a[i] < z:
					fl = False
					break
			if fl:
				l = mid + 1
			else:
				end = mid - 1
		print(end)
solve()


(n, z) = map(int, input().split())
li = sorted(list(map(int, input().split())))
(i, j) = (0, n // 2)
count = 0
n = len(li)
while i < n // 2 and j < n:
	if li[j] - li[i] >= z:
		count += 1
		i += 1
		j += 1
	else:
		j += 1
print(count)


def ans(array, z):
	array.sort()
	left = 0
	right = n // 2 + 1
	while right - left > 1:
		mid = (left + right) // 2
		good = True
		for i in range(mid):
			good &= array[n - mid + i] - array[i] >= z
		if good:
			left = mid
		else:
			right = mid
	return left
(n, z) = map(int, input().split())
a = list(map(int, input().split()))
print(ans(a, z))


def main():
	from sys import stdin, stdout

	def read():
		return stdin.readline().rstrip('\n')

	def read_array(sep=None, maxsplit=-1):
		return read().split(sep, maxsplit)

	def read_int():
		return int(read())

	def read_int_array(sep=None, maxsplit=-1):
		return [int(a) for a in read_array(sep, maxsplit)]

	def write(*args, **kwargs):
		sep = kwargs.get('sep', ' ')
		end = kwargs.get('end', '\n')
		stdout.write(sep.join((str(a) for a in args)) + end)

	def write_array(array, **kwargs):
		sep = kwargs.get('sep', ' ')
		end = kwargs.get('end', '\n')
		stdout.write(sep.join((str(a) for a in array)) + end)
	(n, z) = read_int_array()
	nums = read_int_array()
	nums.sort()
	out = 0
	used = [False] * n
	(i, j) = (0, len(nums) // 2)
	while i < n:
		used[i] = True
		while j < n and (used[j] or nums[j] - nums[i] < z):
			j += 1
		if j == n:
			break
		used[j] = True
		while i < n and used[i]:
			i += 1
		out += 1
	write(out)
main()


from bisect import bisect_left
(n, k) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
now = temp = n // 2
cnt = 0
for i in range(temp):
	while now != n and x[now] - x[i] < k:
		now += 1
	if now == n:
		break
	cnt += 1
	now += 1
print(cnt)


import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	(n, z) = nm()
	a = sorted(nm())
	(ok, ng) = (0, n // 2 + 1)
	while ng - ok > 1:
		mid = (ok + ng) // 2
		p = a[:mid]
		q = a[-mid:]
		for (y, x) in zip(q, p):
			if y - x < z:
				ng = mid
				break
		else:
			ok = mid
	print(ok)
	return
solve()


(n, z) = map(int, input().split())
x = sorted(list(map(int, input().split())))
ost = []
number = 0
for i in range(n // 2):
	ost.append(x[i])
j = 0
length = len(ost)
for i in range(n // 2, n):
	if j < length and x[i] - x[j] >= z:
		j += 1
		number += 1
print(number)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, z) = mp()
l = li()
l.sort()
(i, j, ans) = (0, n // 2, 0)
while j < n and i < n // 2:
	if abs(l[j] - l[i]) < z:
		j += 1
	else:
		ans += 1
		i += 1
		j += 1
pr(ans)


(n, z) = map(int, input().split())
x = [*map(int, input().split())]
x.sort()
l = 0
r = n // 2 + 1
while r - l > 1:
	m = (l + r) // 2
	check = 1
	for i in range(m):
		check &= x[n - m + i] - x[i] >= z
	if check:
		l = m
	else:
		r = m
print(l)


(n, z) = [int(i) for i in input().split(' ')]
nums = [int(i) for i in input().split(' ')]
nums.sort()
if n % 2 == 0:
	odd = nums[:n // 2]
	even = nums[n // 2:]
else:
	odd = nums[:n // 2]
	even = nums[n // 2 + 1:]
(i, j) = (0, 0)
res = 0
while i < len(odd) and j < len(even):
	if abs(odd[i] - even[j]) >= z:
		res += 1
		i += 1
		j += 1
	else:
		j += 1
print(res)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
ans = 0
(i, j) = (0, n // 2)
l = []
a.sort()
while i < n // 2 and j < n:
	if a[j] - a[i] >= k:
		ans += 1
		i += 1
		j += 1
	else:
		j += 1
print(ans)


import sys
input = sys.stdin.readline
(N, Z) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
l = 0
r = N // 2 + 1
while r - l > 1:
	m = (l + r) // 2
	ok = True
	for i in range(m):
		if A[i + N - m] - A[i] < Z:
			ok = False
	if ok:
		l = m
	else:
		r = m
print(l)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	(n, z) = num_input()
	arr = list_input()
	arr.sort()
	pairs = 0
	i = 0
	j = 0
	while i < n // 2 and j < n:
		if arr[i] + z <= arr[j]:
			pairs += 1
			i += 1
		j += 1
	print(pairs)
t = 1
for _ in range(t):
	solve()


(n, z) = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
count = 0
i = 0
j = n // 2
while i < n // 2 and j < n:
	if x[j] - x[i] >= z:
		count += 1
		i += 1
	j += 1
print(count)


def check(num):
	first = l[0:num]
	second = l[n - num:n]
	for i in range(num):
		if second[i] - first[i] < m:
			return False
	return True
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
low = 0
high = n // 2
while low < high:
	mid = (low + high) // 2
	if check(mid):
		low = mid + 1
	else:
		high = mid - 1
if check(low):
	print(low)
else:
	print(low - 1)


(_, z) = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
pos = -1
for i in range(len(p) // 2, len(p)):
	if p[i] >= p[0] + z:
		pos = i
		break
if pos == -1:
	print(0)
else:
	r = pos
	l = 0
	ctr = 0
	while True:
		if l == pos:
			break
		if r == len(p):
			break
		if p[r] >= p[l] + z:
			ctr += 1
			r += 1
			l += 1
		else:
			r += 1
	print(ctr)


nzint = input().split()
nz = [int(x) for x in nzint]
input_string = input().split()
intlist = [int(x) for x in input_string]
intlist.sort()
(i, j) = (nz[0] - 1, nz[0] // 2 - 1)
count = 0
while i >= nz[0] // 2 - 1 and j >= 0:
	if intlist[i] - intlist[j] >= nz[1]:
		count = count + 1
		i = i - 1
	j = j - 1
print(count)


import sys
input = sys.stdin.readline
(n, z) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = 0
r = n // 2 + 1
while r - l > 1:
	mid = (l + r) // 2
	ok = True
	for i in range(mid):
		ok &= x[n - mid + i] - x[i] >= z
	if ok:
		l = mid
	else:
		r = mid
print(l)


(n, z) = list(map(int, input().split()))
x = sorted(map(int, input().split()))
(res, i, j) = (0, 0, n // 2)
while i < n // 2 and j < n:
	if x[i] + z <= x[j]:
		i += 1
		res += 1
	j += 1
print(res)


(n, z) = map(int, input().split())
u = list(map(int, input().split()))
u.sort()
ans = 0
i = 0
j = n // 2
while i < n // 2 and j < n:
	if u[j] - u[i] >= z:
		ans += 1
		i += 1
	j += 1
print(ans)


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = 0
j = len(a) // 2
count = 0
while j < len(a):
	if abs(a[i] - a[j]) >= y:
		count += 1
		a[i] = -1
		a[j] = -1
	else:
		j += 1
	while i < len(a) and a[i] == -1:
		i += 1
	while j < len(a) and (a[j] == -1 or j <= i):
		j += 1
print(count)


def main():
	(n, z) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	(left, right, ret) = (0, n // 2, 0)
	while left <= right:
		mid = (left + right) // 2
		flag = True
		for i in range(mid):
			if a[n - mid + i] - a[i] < z:
				flag = False
				break
		if flag:
			left = mid + 1
			ret = max(ret, mid)
		else:
			right = mid - 1
	print(ret)
main()


(n, z) = map(int, input().split())
a = [int(x) for x in input().split()]
A = sorted(a)
A.sort()
a = 0
b = n // 2
while a < b:
	mid = (a + b + 1) // 2
	if all((A[-mid + ind] - A[ind] >= z for ind in range(mid))):
		a = mid
	else:
		b = mid - 1
print(a)


from __future__ import print_function
import math
import collections
import bisect
(n, z) = map(int, input().split())
x = map(int, input().split())
x = [v for v in x]
x.sort()
ans = 0
(l, r) = (0, n)
while l < r:
	mid = (l + r) // 2
	(i, j) = (0, mid)
	cnt = 0
	while i < mid and j < n:
		if x[i] + z <= x[j]:
			i += 1
			j += 1
			cnt += 1
		else:
			j += 1
	if i == mid:
		l = mid + 1
	else:
		r = mid
	ans = max(ans, cnt)
print(ans)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self, _map=str):
		return list(map(_map, sys.stdin.readline().split()))

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		z = self.next_int()
		x = sorted([self.next_int() for _ in range(0, n)])
		low = 0
		high = n
		while high - low > 1:
			mid = (low + high) // 2
			if self.test(mid, n, x, z):
				low = mid
			else:
				high = mid
		print(low)

	def test(self, mid, n, x, z):
		j = mid
		for i in range(0, mid):
			while j < n and x[j] < x[i] + z:
				j += 1
			if j >= n:
				return False
			j += 1
		return True
Main().solve()


o = lambda *a: (lambda *b: a[0](*b)) if len(a) == 1 else lambda *b: a[0](o(*a[1:])(*b))
lmap = o(list, map)
lmap_ = lambda f: lambda L: lmap(f, L)
spp = lambda n: lambda x: lambda a: [y for y in a.split(x) if len(y) >= n]

def P(S):
	(n, z, S) = (S[0][0], S[0][1], sorted(S[1]))
	(l, r, m2) = (0, n // 2, 0)
	while l <= r:
		m = (l + r) // 2
		f = True
		for i in range(m):
			f *= S[n - m + i] - S[i] >= z
		if f:
			l = m + 1
		else:
			r = m - 1
	print(r)
import sys
o(P, lmap_(lmap_(int)), lmap_(spp(0)(' ')), spp(1)('\n'))(sys.stdin.read())


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
done = [0] * n
ans = 0
st = 0
end = 1
while end < n:
	if l[end] - l[st] < m:
		end += 1
	else:
		ans += 1
		done[end] = 1
		end += 1
		st += 1
		while done[st] == 1:
			st += 1
			if st == n:
				break
		if st == n:
			break
end = n - 1
ans1 = 0
for i in range(n // 2 - 1, -1, -1):
	if l[end] - l[i] >= m:
		ans1 += 1
		end -= 1
print(max(ans1, ans))


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	from bisect import bisect_left
	input = sys.stdin.readline
	(N, z) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	B = A[:N // 2]
	C = A[(N + 1) // 2:]
	cnt = [0] * (N // 2)
	for i in range(1, N // 2 + 1):
		b = B[-i]
		j = bisect_left(C, b + z)
		if j != N // 2:
			cnt[j] += 1
	ans = 0
	room = 0
	for j in range(1, N // 2 + 1):
		if cnt[-j]:
			ans += 1
			cnt[-j] -= 1
			if room:
				k = min(room, cnt[-j])
				ans += k
				room -= k
		else:
			room += 1
	print(ans)
main()


(n, d) = map(int, input().split())
m = list(map(int, input().split()))
m.sort()
l = 0
r = n // 2 + 1
while l + 1 < r:
	mi = (l + r) // 2
	norm = True
	for i in range(mi):
		if m[i] + d > m[n - mi + i]:
			norm = False
	if norm:
		l = mi
	else:
		r = mi
print(l)


(n, z) = [int(x) for x in input().split()]
b = sorted([int(x) for x in input().split()])
a = []
for item in b:
	a.append([item, 0])
end = n // 2
counter = 0
for i in range(n):
	if end == i:
		end += 1
	for j in range(end, n):
		if a[j][0] - a[i][0] >= z and a[j][1] == a[i][1] == 0:
			end = j
			counter += 1
			a[i][1] = a[j][1] = 1
			break
	else:
		end = j
print(counter)


(n, z) = map(int, input().split())
numbers = sorted(list(map(int, input().split())))
(matches, a, b) = (0, 0, n // 2)
while a < n // 2 and b < n:
	if numbers[a] + z <= numbers[b]:
		matches += 1
		a += 1
	b += 1
print(matches)


inp = input().strip()
(n, z) = (int(inp.split(' ')[0]), int(inp.split(' ')[1]))
inp = input()
inp_arr = inp.strip().split(' ')
a = [int(i) for i in inp_arr]
a.sort(reverse=True)
f = 0
l = n // 2
c = 0
while l < n and f < n // 2:
	if a[f] - a[l] >= z:
		f = f + 1
		l = l + 1
		c = c + 1
	else:
		l = l + 1
print(c)


(n, z) = map(int, input().split())
x = sorted(list(map(int, input().split())))
ok = 0
ng = n // 2 + 1
while ng - ok > 1:
	mid = (ok + ng) // 2
	cnt = 0
	for i in range(mid):
		if x[n - mid + i] - x[i] >= z:
			cnt += 1
	if cnt == mid:
		ok = mid
	else:
		ng = mid
print(ok)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if len(a) % 2 == 0:
	x = len(a) // 2
else:
	x = len(a) // 2 + 1
i = 0
while x < len(a):
	if a[x] - a[i] >= k:
		i += 1
	x += 1
print(i)


(n, z) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
beg = n // 2
cnt = 0
for i in range(n // 2):
	low = beg
	high = n - 1
	while low < high:
		mid = (low + high) // 2
		if lst[mid] - lst[i] >= z:
			high = mid
		elif lst[mid] - lst[i] < z:
			low = mid + 1
	if low == n - 1:
		if lst[low] - lst[i] >= z:
			cnt = cnt + 1
		break
	beg = low + 1
	cnt = cnt + 1
print(cnt)


(n, x) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
taken = [0] * n
r = n // 2
ans = 0
for i in range(n):
	if taken[i]:
		continue
	while r < n and A[r] - A[i] < x:
		r += 1
		while r < n and taken[r]:
			r += 1
	if r < n and A[r] - A[i] >= x:
		taken[r] = 1
		ans += 1
		r += 1
	taken[i] = 1
print(ans)


(n, z) = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
t = 0
a = 0
b = n // 2
while a < n // 2 and b < n:
	if x[b] - x[a] >= z:
		t += 1
		a += 1
	b += 1
print(t)


n_and_z = [int(x) for x in input().split()]
n_integers = [int(x) for x in input().split()]
n_integers.sort()
first_half = int(n_and_z[0] / 2)
counter = 0
z = first_half
for x in range(0, first_half):
	for y in range(z, len(n_integers)):
		if n_integers[y] - n_integers[x] >= n_and_z[1]:
			counter = counter + 1
			z = y + 1
			break
	if y == len(n_integers) - 1:
		break
print(counter)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
(nb_elem, min_diff) = RMI()
elems = sorted(RMI())
mids = nb_elem // 2
(left, rite, ans) = (0, mids, 0)
while left < mids and rite < nb_elem:
	if elems[left] + min_diff <= elems[rite]:
		left += 1
		ans += 1
	rite += 1
print(ans)


(n, z) = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
l = n // 2 - 1
r = n - 1
m = (l + r) // 2
cnt = 0
for i in range(l, -1, -1):
	if X[r] - X[l] >= z:
		cnt += 1
		l -= 1
		r -= 1
	else:
		l -= 1
print(cnt)


(n, z) = list(map(int, input().split()))
l = list(map(int, input().split()))
l = sorted(l)
wyn = 0
maly = 0
duzy = n // 2
zaj = [0] * n
while duzy < n:
	while maly < n:
		if zaj[maly] == 1:
			maly += 1
		else:
			break
	if l[duzy] - l[maly] >= z and zaj[duzy] == 0 and (zaj[maly] == 0):
		wyn += 1
		maly += 1
		zaj[maly - 1] = 1
		zaj[duzy] = 1
	duzy += 1
print(wyn)


(n, z) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = -1
h = len(a) // 2 - 1
j = h
m = 0
while i < h:
	i = i + 1
	j = j + 1
	while j < len(a) and a[j] - a[i] < z:
		j = j + 1
	if j >= len(a):
		break
	m = m + 1
print(m)


from collections import *
from math import *
(n, z) = map(int, input().split())
a = list(map(int, input().split()))
vis = [0 for i in range(n)]
a.sort()
i = 0
j = n // 2
ct = 0
while j < n:
	if vis[i] == 1:
		i += 1
	elif a[j] - a[i] >= z:
		ct += 1
		vis[i] = 1
		vis[j] = 1
		i += 1
		j += 1
	else:
		j += 1
print(ct)


a = [int(i) for i in input().split()]
n = a[0]
z = a[1]
arr = [int(i) for i in input().split()]
arr.sort()
count = 0
l = 0
r = n // 2 + 1
while r - l > 1:
	mid = (l + r) // 2
	ans = True
	for i in range(mid):
		ans &= arr[n - mid + i] - arr[i] >= z
	if ans:
		l = mid
	else:
		r = mid
print(l)


(n, x) = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
nums.sort()
left = 0
right = n + 1
count = 0
while True:
	if right - left <= 1 or right <= (n + 1) // 2:
		break
	c = 0
	ok = True
	mid = int((left + right) / 2)
	for i in range(n - mid):
		if nums[mid + i] - nums[i] >= x:
			c += 1
		else:
			ok = False
			break
	if not ok:
		left = mid
	else:
		right = mid
		if c > count:
			count = c
ok = True
c = 0
for i in range(n - left):
	if nums[left + i] - nums[i] >= x:
		c += 1
	else:
		ok = False
		break
if ok:
	if c > count and c <= (n + 1) // 2:
		count = c
ok = True
c = 0
for i in range(n - right):
	if nums[right + i] - nums[i] >= x:
		c += 1
	else:
		ok = False
		break
if ok:
	if c > count and c <= (n + 1) // 2:
		count = c
print(count)


(n, z) = map(int, input().split())
s = sorted(list(map(int, input().split())))
q = [True for n in range(n)]
rt = 0
i = 0
j = n // 2
while i < n and j < n:
	while j < n and s[i] + z > s[j]:
		j += 1
	if i < j < n and q[i] and q[j]:
		q[i] = False
		q[j] = False
		rt += 1
	i += 1
	j += 1
print(rt)


(n, z) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
cnt = 0
begin = len(lst) // 2
for i in range(len(lst) // 2):
	if begin > len(lst) - 1:
		break
	elif lst[begin] - lst[i] >= z:
		cnt = cnt + 1
		begin = begin + 1
		continue
	else:
		while begin <= len(lst) - 1:
			if lst[begin] - lst[i] >= z:
				cnt = cnt + 1
				begin = begin + 1
				break
			else:
				begin = begin + 1
print(cnt)


from sys import stdin, stdout

def solve(arr, minDiff):
	arr = sorted(arr)
	l = 0
	if len(arr) % 2 == 0:
		r = len(arr) // 2
		rr = len(arr) // 2
	else:
		r = len(arr) // 2
		rr = len(arr) // 2
	counter = 0
	i = 0
	while i < r and rr < len(arr):
		if arr[rr] - arr[i] >= minDiff:
			counter += 1
			i += 1
		rr += 1
	return counter
(n, z) = map(int, input().split())
ar = [int(x) for x in input().split()]
stdout.write(str(solve(ar, z)))


import bisect
(n, z) = map(int, input().split())
x = [int(i) for i in input().split()]
x.sort()
ans = 0
j = -1
for i in range(n // 2 - 1, -1, -1):
	if x[j] - x[i] >= z:
		j -= 1
		ans += 1
print(ans)


def max_pairs(arr, z):
	count = 0
	N = len(arr)
	arr.sort()
	i = 0
	mid = N // 2 + (1 if N % 2 else 0)
	j = mid
	while i < mid and j < N:
		while j < N and arr[j] - arr[i] < z:
			j += 1
		if j != N:
			count += 1
		i += 1
		j += 1
	return count

def main():
	(n, z) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	print(max_pairs(arr, z))
main()


(N, Z) = list(map(int, input().split()))
A = sorted([int(a) for a in input().split()])
(l, r) = (0, N // 2 + 1)
while r - l > 1:
	m = (r + l) // 2
	for i in range(m):
		if A[N - m + i] - A[i] < Z:
			r = m
			break
	else:
		l = m
print(l)


(n, z) = map(int, input().split())

def can(x, c):
	for (a, b) in zip(x[:c], x[-c:]):
		if a + z > b:
			return False
	return True
x = [int(x) for x in input().split()]
x.sort()
l = 0
r = n // 2 + 1
while r - l > 1:
	mid = (l + r) // 2
	if can(x, mid):
		l = mid
	else:
		r = mid
print(l)


(n, z) = input().split()
n = int(n)
z = int(z)
nums = list(map(int, input().split()))
nums.sort()
l1 = nums[:n // 2]
l2 = nums[n // 2:]
count = 0
ptr1 = 0
ptr2 = 0
while ptr2 < len(l2) and ptr1 < len(l1):
	if l2[ptr2] - l1[ptr1] >= z:
		count += 1
		ptr1 += 1
		ptr2 += 1
	else:
		ptr2 += 1
print(count)


(n, z) = map(int, input().split())
arrs = [int(x) for x in input().split()]
arrs.sort()

def fi():
	j = len(arrs) // 2
	while arrs[j] - arrs[0] < z and j < len(arrs) - 1:
		j += 1
	l = 0
	r = j
	arr = arrs[:]
	cnt = 0
	while r != len(arr):
		if arr[l] == 10 ** 10:
			l += 1
		elif arr[r] - arr[l] >= z:
			arr[r] = 10 ** 10
			cnt += 1
			r += 1
			l += 1
		else:
			r += 1
	return cnt
print(fi())


(n, z) = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = a[:n // 2]
a = a[n // 2:]
i = 0
j = 0
ans = 0
while i < len(b) and j < len(a):
	if a[j] - b[i] >= z:
		ans += 1
		i += 1
		j += 1
	else:
		j += 1
print(ans)


(n, z) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
mid = (n - 2) // 2
cur = n - 1
ans = 0
for i in range(mid, -1, -1):
	if arr[i] + z <= arr[cur]:
		cur -= 1
		ans += 1
print(ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = a[:n // 2]
c = a[n // 2:]
j = 0
ans = 0
for i in b:
	while abs(i - c[j]) < m:
		j += 1
		if j == len(c):
			print(ans)
			exit()
	ans += 1
	j += 1
	if j == len(c):
		print(ans)
		exit()
print(ans)


(n, z) = map(int, input().split(' '))
nums = list(map(int, input().split(' ')))
nums.sort()
l = 0
r = n // 2 + 1
while r - l > 1:
	m = (l + r) // 2
	found = True
	for i in range(0, m):
		found &= nums[n - m + i] - nums[i] >= z
	if found:
		l = m
	else:
		r = m
print(l)


import sys
(n, z) = list(map(int, sys.stdin.readline().strip().split()))
x = list(map(int, sys.stdin.readline().strip().split()))
x.sort()
i = 0
j = n // 2
c = 0
while j < n and i < n // 2:
	if x[j] - x[i] >= z:
		i = i + 1
		j = j + 1
		c = c + 1
	else:
		j = j + 1
print(c)


(n, z) = (int(x) for x in input().split(' '))
nums = [int(x) for x in input().split(' ')]
nums.sort()
out = 0
left = 0
right = 1
while right < n and left < n // 2:
	if nums[right] - nums[left] >= z:
		left += 1
		out += 1
	right += 1
print(out)


(n, x) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.sort()
taken = [0] * n
lo = 0
hi = n // 2 + 1

def check(sz):
	if sz > n // 2:
		return 0
	left = A[:sz]
	right = A[-sz:]
	ok = 1
	for i in range(len(left)):
		if right[i] - left[i] >= x:
			continue
		else:
			ok = 0
	return ok
for i in range(200):
	mid = (lo + hi) // 2
	if check(mid):
		lo = mid
	else:
		hi = mid
ans = 0
for i in range(max(0, lo - 5), min(hi + 5, n // 2)):
	if check(i):
		ans = i
	else:
		break
print(mid)


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	(n, k) = cin()
	a = ain()
	a.sort()
	b = a[:n // 2]
	c = a[n // 2:]
	ans = p = 0
	for i in b:
		j = i + k
		while p < len(c):
			if c[p] >= j:
				p += 1
				ans += 1
				break
			p += 1
	print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


(n, z) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = n // 2
cnt = 0
while l < n // 2 and r < n:
	if a[r] - a[l] >= z:
		cnt += 1
		r += 1
		l += 1
	else:
		r += 1
print(cnt)


(n, z) = (int(i) for i in input().split())
k = 0
x = sorted([int(i) for i in input().split()])
(i, j) = (0, n // 2)
while i < n // 2 and j < n:
	if x[j] - x[i] >= z:
		i += 1
		k += 1
	j += 1
print(k)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10)]
pp = [0] * 10

def SieveOfEratosthenes(n=10):
	p = 2
	c = 0
	while p * p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				pp[i] += 1
				prime[i] = False
		p += 1

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[n - 1]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = arr[mid]
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[0]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = arr[mid]
			left = mid + 1
	return res
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
done = [0] * n
res = 0
j = n // 2
while j < n and a[j] - a[0] < k:
	j += 1
if j == n:
	print(0)
	sys.exit(0)
res = 1
done[0] = done[j] = 1
j += 1
for i in range(1, n // 2):
	if done[i]:
		continue
	j = max(j, i + 1)
	while j < n and a[j] - a[i] < k:
		j += 1
	if j == n:
		break
	done[i] = done[j] = 1
	j += 1
	res += 1
print(res)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def bfs(adj, peoples):
	stack = [0]
	order = []
	parent = [-1] * len(adj)
	subt = peoples[:]
	while stack:
		v = stack.pop()
		order.append(v)
		for dest in adj[v]:
			if parent[v] == dest:
				continue
			parent[dest] = v
			stack.append(dest)
	for v in reversed(order):
		if v != 0:
			subt[parent[v]] += subt[v]
	return (order, subt, parent)

def main():
	(n, z) = map(int, input().split())
	a = sorted(map(int, input().split()))
	(ok, ng) = (0, (n >> 1) + 1)
	while abs(ok - ng) > 1:
		mid = ok + ng >> 1
		if all((a[n - mid + i] - a[i] >= z for i in range(mid))):
			ok = mid
		else:
			ng = mid
	print(ok)
main()


import math

def can(arr, count, min_dist):
	for i in range(count):
		if arr[len(arr) - count + i] - arr[i] < min_dist:
			return False
	return True

def binsearch(arr, from_, to_, min_dist):
	arr.sort()
	if from_ == to_:
		return from_
	mid = math.ceil((to_ + from_) / 2)
	if can(arr, mid, min_dist):
		return binsearch(arr, mid, to_, min_dist)
	else:
		return binsearch(arr, from_, mid - 1, min_dist)
(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
print(binsearch(arr, 0, n // 2, k))


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()

def check(mi):
	try:
		if 2 * mi > n:
			return 0
		l1 = [l[i] for i in range(mi)]
		l2 = [l[i] for i in range(n - mi, n)]
		for i in range(mi):
			if l1[i] + k > l2[i]:
				return 0
		return 1
	except:
		return 0
lo = 1
hi = n // 2
ans = 0
while lo <= hi:
	mi = lo + hi >> 1
	if check(mi):
		ans = mi
		lo = mi + 1
	else:
		hi = mi - 1
print(ans)


(n, k) = map(int, input().split())
b = sorted(list(map(int, input().split())))
i = 0
j = 0
s = 0
while i < n // 2 and j < n:
	if b[i] + k <= b[j]:
		s += 1
		i += 1
	j += 1
print(s)


def solve(v, z):
	n = len(v)
	v.sort()

	def construct(k):
		res = True
		for f in range(n - 1, n - k - 1, -1):
			low = f - n + k
			if v[f] < v[low] + z:
				res = False
				break
		return res
	lo = 0
	hi = n // 2
	while hi - lo > 0:
		if hi - lo == 1:
			return hi if construct(hi) else lo
		mid = (hi + lo) // 2
		if construct(mid):
			lo = mid
		else:
			hi = mid
	return lo
(n, z) = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
print(solve(v, z))


(n, z) = map(int, input().split())
a = [int(x) for x in input().split()]
x = sorted(a)
(res, i, j) = (0, 0, n // 2)
while i < n // 2 and j < n:
	if x[i] + z <= x[j]:
		i += 1
		res += 1
	j += 1
print(res)


(n, z) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
vis = [False] * n
j = n // 2
for i in range(n // 2):
	if vis[i]:
		continue
	while j < n and A[j] - A[i] < z:
		j += 1
	if j == n:
		break
	vis[j] = True
	j += 1
	ans += 1
print(ans)


(n, z) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
a.sort()
res = 0

def can_match(k):
	if 2 * k > n:
		return False
	if k == 0:
		return True
	b = a[:]
	j = k
	for i in range(n):
		if b[i] != -1:
			while j < n and (j <= i or b[j] == -1 or b[j] < b[i] + z):
				j += 1
			if j < n:
				b[i] = -1
				b[j] = -1
				k -= 1
				if k == 0:
					return True
			else:
				break
	return False
(l, r) = (0, n)
while l < r:
	m = (l + r) // 2
	if can_match(m):
		l = m + 1
	else:
		r = m
print(l - 1)


import bisect
import sys
input = sys.stdin.readline

def solve(mid):
	for i in range(mid):
		if a[n - mid + i] - a[i] < z:
			return False
	return True
(n, z) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ok = 0
ng = n // 2 + 1
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	if solve(mid):
		ok = mid
	else:
		ng = mid
print(ok)


from bisect import bisect_left, bisect_right
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def judge(x):
	flg = 1
	for i in range(x):
		if a[i] + k > a[i + n - x]:
			flg = 0
			break
	if flg:
		return True
	else:
		return False
l = 0
r = n // 2 + 1
while l + 1 < r:
	x = (l + r) // 2
	if judge(x):
		l = x
	else:
		r = x
print(l)


(n, m) = map(int, input().split())
ll = list(map(int, input().split()))
ll.sort()
f = 0
l = n // 2 + 1
while l - f > 1:
	mid = (f + l) // 2
	flag = True
	for i in range(mid):
		flag = flag & (ll[n - mid + i] - ll[i] >= m)
	if flag:
		f = mid
	else:
		l = mid
print(f)