d=[0]*6**8

n,k,*a=list(map(int,open(0).read().split()+d))

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

print((max(d)))
d=[0]*6**8

n,k,*a=list(map(int,open(0).read().split()))

a=d+a

while n:d[n]=max(d[j]for j in range(n,n+99)if abs(a[-n]-a[-j])<=k)+1;n-=1

print((max(d)))
d = [0] * 6**8
n, k, *a = list(map(int, open(0).read().split() + d))
for i in range(n):
    d[i] = max(d[j] for j in range(i - 99, i + 1) if abs(a[i] - a[j]) <= k) + 1
print((max(d)))

d = [0] * 6**8
n, k, *a = list(map(int, open(0).read().split()))
a = d + a
while n:
    d[n] = max(d[j] for j in range(n, n + 99) if abs(a[-n] - a[-j]) <= k) + 1
    n -= 1
print((max(d)))

-n, k, *a = list(map(int, open(0).read().split() + d)) -for i in range(n): -    d[i] = max(d[j] for j in range(i - 99, i + 1) if abs(a[i] - a[j]) <= k) + 1 +n, k, *a = list(map(int, open(0).read().split())) +a = d + a +while n: +    d[n] = max(d[j] for j in range(n, n + 99) if abs(a[-n] - a[-j]) <= k) + 1 +    n -= 1