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: interview

Starter code:

Solutions:
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,K = list(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)


# Please DON'T hack me! TY!
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(next(self))

    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


def __starting_point():
    Main().solve()

__starting_point()

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)

_, 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:
    # print(z, p, pos)
    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)


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)






# -*- coding: utf-8 -*-

def __starting_point():
    n, z = map(int, input().split())
    a = list(map(int, input().split()))
    # print(n, z)
    a.sort()
    # print(a)
    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
            # print("start: {}, a[start]: {}, end: {}, a[end]: {}".\
            #     format(start, a[start], end, a[end]))
            start -= 1
            end -= 1
            res += 1 
        else:
            if (mask[start]==1):
                start -= 1
            elif mask[end]==1:
                end -= 1
            else:
                start -= 1
        if start<0:
            break
            
    print(res)
__starting_point()

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,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)
               return
print(s)

n, z = list(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())




from bisect import bisect_left
n,k = list(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)


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 = int(input())
# arr = list(map(int, input().split()))
#
# #circle 1
# #triangle 2
# # square 3
# dic = {(1,1): "I", (1,2):3, (1,3):4, (2,1):3, (2,2):"I", (2,3):"I", (3,1):4, (3,2):"I", (3,3):"I"}
#
# c = 0
# for i in range(len(arr)-1):
#     if dic[(arr[i], arr[i+1])] == "I":
#         print("Infinite")
#         return
#     else:
#         c += dic[(arr[i], arr[i+1])]
#
# print("Finite")
# print(c)

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)):
    # print(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)

# from collections import Counter
# n = int(input())
#
#
# for _ in range(n):
#     word = input()
#     nC = [0]*27
#     for i in word:
#         nC[ord(i)%97] += 1
#     wordN = ""+word[0]
#     nC[ord(word[0])%97] -= 1
#     print(nC, wordN)
#     while len(wordN) < len(word):
#         lastidx = ord(wordN[-1])%97
#         flag = True
#         for i in range(len(nC)-1, -1, -1):
#             if i == lastidx+1 or i == lastidx-1:
#                 continue
#             else:
#                 if nC[i] > 0:
#                     wordN += chr(i+97)
#                     nC[i] -= 1
#                     flag = False
#                     break
#         if flag:
#             print("No answer")
#             break
#     print(wordN)
#     if not flag:
#         print(wordN)


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)

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))


# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 21:33:01 2019

@author: Z

4
abcd
gg
codeforces
abaca


"""


from fractions import gcd

from collections import Counter


def main():
    n,z = [int(a) for a in input().split()]
    #z = int(input())
    nums= [int(a) for a in input().split()]
    nums.sort()
    if n%2==0:
        x1 = nums[:n//2]
        x2 = nums[n//2:]
    else:
        x1 = nums[:n // 2]
        x2 = nums[n // 2+1:]
    n = n//2
    cnt = 0;
    i = 0;
    j = 0;
    while i<n and j<n:
        while(j<n and x2[j]<x1[i]+z):
            j+=1
        if (j<n):
            cnt+=1
            i+=1
            j+=1
    print(cnt)







def __starting_point():

    main()

__starting_point()

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
            #print(i,j)

    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)))

    
    
    


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)



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 = [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)

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()


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 = 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 = 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 = 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)):
	#print(l2[ptr2]-l1[ptr1])
	#print(z)
	if((l2[ptr2]-l1[ptr1])>=z):
		count+=1
		ptr1+=1
		ptr2+=1
	else:
		ptr2+=1
print(count)