We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. 

The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.

Diameter of multiset consisting of one point is 0.

You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?


-----Input-----

The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively.

The second line contains n space separated integers (1 ≤ x_{i} ≤ 100) — the coordinates of the points.


-----Output-----

Output a single integer — the minimum number of points you have to remove.


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

Output
1

Input
3 0
7 7 7

Output
0

Input
6 3
1 3 4 6 9 10

Output
3



-----Note-----

In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.

In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. 

In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.

Difficulty: interview

Starter code:

Solutions:
import sys

def read_int():
    return int(input())

def read_ints():
    return [int(x) for x in input().split()]

n, d = read_ints()
a = read_ints()

a = sorted(a)

best = 0

for i in range(n):
    for j in range(i, n):
        if a[j] - a[i] <= d:
            best = max(best, j - i + 1)

print(len(a) - best)




n, d = list(map(int, input().split()))

A = sorted([int(x) for x in input().split()])

result = n

for i in range(n):
    for j in range(i, n):
        if A[j] - A[i] <= d:
            result = min([result, i + n - j - 1])

print(result)


from sys import stdin, stdout
from random import randrange

n, d = map(int, stdin.readline().split())
points = sorted(list(map(int, stdin.readline().split())))
ans = n

for i in range(n):
    for j in range(n - 1, i - 1, -1):
        if points[j] - points[i] <= d:
            ans = min(ans, n - (j - i + 1))

stdout.write(str(ans))

n, d = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
l=0
r = 0
ans = 0
while r < n:
    if a[r]-a[l] <= d:
        ans= max(ans, r-l+1)
        r += 1
    else:
        l+=1
print(n-ans)

n, d = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = n - 1
for i in range(len(a)):
	j = i
	while j < len(a) and a[j] - a[i] <= d:
		j += 1
	ans = min(ans, n - (j - i))
print(ans)

n, d = (int(x) for x in input().split())

ps = sorted([int(x) for x in input().split()])

r = 1000

for st in range(1, 110):
    fn = st + d
    rr = len([x for x in ps if x < st or x > fn])
    if rr < r:
        r = rr
print(r)

f=input()
n,d=f.split()
n,d=int(n),int(d)
f=input()
a=f.split()
a=[int(k) for k in a]
#a.sort()

ans=0
count=0

for i in range(len(a)):
	count=0
	for j in range(len(a)):
		if (a[i]<=a[j]<=a[i]+d):
			count+=1
	if count>ans:
		ans=count

print(len(a)-ans)

number, diameter = [int(x) for x in input().split()]
numbers = [int(x) for x in input().split()]
numbers.sort()

max_covered = 0
for i in range(len(numbers)):
	j = i
	while j != len(numbers) and abs(numbers[i] - numbers[j]) <= diameter:
		j += 1
	max_covered = max(j - i, max_covered)

print(len(numbers) - max_covered)

n,d=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
for i in range(1,n+1):
    for j in range(i):
        if a[n-i+j]-a[j]<=d:
            print(i-1)
            return


n, d = map(int, input().split());
A = list(map(int, input().split()));
d = d + 1;
B = [];
for q in range(101):
    B.append(0);
for q in range(n):
    B[A[q]] += 1;
#print(*B);
res = 0;
for q in range(d):
    res = res + B[q];
#print(res);
ans = res;
for q in range(d, 101):
    res = res + B[q] - B[q - d];
    ans = max(res, ans);
print(n - ans);

n, d = list(map(int, input().split()))
arr = [int(x) for x in input().split()]
arr.sort()
start = 0
end = 0
mx = 0
while end < n:
    while end < n and arr[end] - arr[start] <= d:
        end += 1
    mx = max(mx, end - start)
    start += 1
    
mx = max(mx, n - start)

print(n - mx)


def solve(d, A):
    if d == 100:
        return 0
    B = [0]*(101)
    for a in A: B[a] += 1
    for i in range(1, 101):
        B[i] += B[i-1]
    M = 0
    for i in range(d+1, 101):
        u = B[i] - B[i-d-1]
        M = max(u, M)
    return len(A) - M

n, d = map(int, input().split())
a = list(map(int, input().split()))
print(solve(d, a))

from copy import copy
raw = [int(x) for x in input().split(' ')]
n= raw[0]
d = raw[1]
a = [int(x) for x in input().split(' ')]
a = sorted(a)

strat = 0
best = 200
going = True

def dimof(li):
	return li[-1]-li[0]

while strat<101 and going:
	c = 0
	temp = a.copy()
	for i in range(strat):
		if dimof(temp) <= d:
			break

		del temp[0]
		c += 1

	if going:
		if dimof(temp) <= d:
			going = False
		else:
			while dimof(temp) > d:
				del temp[-1]
				c+=1

	if c < best:
		best = c
	strat += 1

print(best)

n, d = map(int,input().split())
multi = list(map(int,input().split()))
multi.sort()
save = [0]*n
for i in range(n):
	j = i+1
	while (j < n and (multi[j]- multi[i])<=d):
		j+=1
	save[i] = j-i
print(n-max(save))

n, d = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
l = 0
r = n - 1
mn = n
for i in range(n):
	l = i
	r = n
	c = a[i] + d
	while r - l > 1:
		mid = (r + l) // 2
		if a[mid] > c:
			r = mid
		else:
			l = mid
	mn = min(mn, n - (l - i + 1))
print(mn)

n, d = list(map(int, input().split()))
L = list(map(int, input().split()))
L.sort()
max = -1
for i in range(n):
    for j in range(i, n):
        if L[j] - L[i] <= d:
            if j - i > max:
                max = j - i
print(n - max - 1)
    


n,d=list(map(int,input().split(' ')))
a=list(map(int,input().split(' ')))
c=0
t=0
l=[]
a.sort()
for i in range(0,n):
    t=0
    for j in range(i,n):
        x=a[j]-a[i]
        if x<=d:
            t+=1
    l.append(t)
print(n-max(l))


from sys import stdin as cin

def main():
    n, m = list(map(int, cin.readline().split()))
    a = list(map(int, cin.readline().split()))
    a.sort()
    x = 0
    y = -1
    for i in range(n):
        if a[i] - a[0] > m:
            y = i
            break
    if y == -1:
        print(0)
        return
    o = n - y
    while y < n:
        x += 1
        while y < n and a[y] - a[x] <= m:
            y += 1
        o = min(n - y + x, o)
    print(o)

main()


n, d = list(map(int, input().split()))
x = list(map(int, input().split()))

print(min(len([yi for yi in x if yi < xi or xi + d < yi]) for xi in x))


q,w=map(int,input().split())
a=list(map(int,input().split()))
s=[0 for i in range(0,q)]
a.sort()
for i in range(0,q-1):
    j=i+1
    while (a[j]-a[i]<=w):
        s[i]+=1
        j+=1
        if j==q:
            break
print(q-max(s)-1)

n, d = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
ans = [[1000000000] * n for i in range(n)]
for l in range(n):
    for r in range(l, n):
        if max(a[l:r + 1]) - min(a[l:r + 1]) <= d:
            ans[l][r] = l + (n - r - 1)
print(min([min(i) for i in ans]))

#!/usr/bin/env python3
from sys import stdin, stdout

def rint():
    return list(map(int, stdin.readline().split()))
#lines = stdin.readlines()


x = [0 for i in range(101)]

n, d = rint()

xin = list(rint())
xin.sort()
for xx in xin:
    x[xx] += 1
if xin[-1] <= d+1:
    print(0)
    return
maxn = 0
for i in range(1,d+2):
    maxn += x[i]

cur = maxn
for i in range(d+2, 101):
    cur = cur - x[i-d-1] + x[i]
    if cur > maxn:
        maxn = cur

print(n-maxn)


def memoize(f):
    memo = {}
    def helper(*x):
        x = tuple(x)
        if x not in memo:
            memo[x] = f(*x)
        return memo[x]
    return helper

n, d, *_ = list(map(int, input().split()))
*x, = list(map(int, input().split()))


x.sort()

@memoize
def solve(d, li, ri):
	if x[ri] - x[li] <= d:
		return 0
	else:
		return min(solve(d, li + 1, ri), solve(d, li, ri - 1)) + 1

print(solve(d, 0, len(x) - 1))


from collections import Counter

n, d = map(int, input().split())
x = sorted(map(int, input().split()))

freq = list(Counter(x).items())
freq.sort(key=lambda pair: pair[0])

toleft = 0
mindrop = n
for i, x in enumerate(freq):
    toleft += freq[i-1][1] if i>0 else 0
    toright = sum([pair[1] for pair in freq[i+1:] if pair[0]>x[0]+d])
    mindrop = min(toleft + toright, mindrop)

print(mindrop)