def op(a,b):

    return max(a,b)



class segmentTree:

    def __init__(self,n,op,init_value):

        dataLen=1 << (n - 1).bit_length()

        self.data=[init_value]*(2*dataLen)

        self.op=op

        self.length=dataLen

    def getIdx(self,left,right):

        idxs=[]

        l=left

        r=right

        while True:

            idx=1

            valueL=0

            valueR=self.length-1

            while l!=valueL or valueR>=r:

                if l<=(valueR+valueL)//2:

                    valueR-=(valueR-valueL+1)//2

                    idx*=2

                else:

                    valueL+=(valueR-valueL+1)//2

                    idx=idx*2+1

            idxs.append(idx)

            if valueR==r-1:

                break

            l=valueR+1

        return idxs

    def get(self,n):

        return self.data[self.getIdx(n,n+1)[0]]



    def set(self,n,value):

        if n<0 or n>=self.length:

          return False

        idx1=self.getIdx(n,n+1)[0]

        self.data[idx1]=value

        while idx1!=1:

            idx2=idx1^1

            if idx1>idx2:

                idx1,idx2=idx2,idx1

            self.data[idx1//2]=self.op(self.data[idx1],self.data[idx2])

            idx1//=2

        return True

    def query(self,l,r):

        idxs=self.getIdx(l,r)

        ret=self.data[idxs[0]]

        for idx in idxs:

            ret=self.op(ret,self.data[idx])

        return ret





N,K=list(map(int,input().split()))

A=[]

for i in range(N):

  A.append(int(eval(input())))



N=300000

seg = segmentTree(N, op, 0)



for i in A:

  l=min(N,max(0,i-K))

  r=max(0,min(N,i+K))

  v=seg.query(l,r+1)

  seg.set(i,v+1)

print((seg.query(0,N)))
def op(a,b):

    return max(a,b)



class segmentTree:

    def __init__(self,n,op,init_value):

        dataLen=1 << (n - 1).bit_length()

        self.data=[init_value]*(2*dataLen)

        self.op=op

        self.length=dataLen

    def getIdx(self,left,right):

        idxs=[]

        l=left

        r=right

        while True:

            idx=1

            valueL=0

            valueR=self.length-1

            while l!=valueL or valueR>=r:

                if l<=(valueR+valueL)//2:

                    valueR-=(valueR-valueL+1)//2

                    idx*=2

                else:

                    valueL+=(valueR-valueL+1)//2

                    idx=idx*2+1

            idxs.append(idx)

            if valueR==r-1:

                break

            l=valueR+1

        return idxs

    def get(self,n):

        return self.data[n+self.length]



    def set(self,n,value):

        idx1=n+self.length

        self.data[idx1]=value

        while idx1!=1:

            idx2=idx1^1

            if idx1>idx2:

                idx1,idx2=idx2,idx1

            self.data[idx1//2]=self.op(self.data[idx1],self.data[idx2])

            idx1//=2

    def query(self,l,r):

        idxs=self.getIdx(l,r)

        ret=self.data[idxs[0]]

        for idx in idxs:

            ret=self.op(ret,self.data[idx])

        return ret





N,K=list(map(int,input().split()))

A=[]

for i in range(N):

  A.append(int(eval(input())))



N=300000

seg = segmentTree(N, op, 0)



for i in A:

  l=min(N,max(0,i-K))

  r=max(0,min(N,i+K))

  v=seg.query(l,r+1)

  seg.set(i,v+1)

print((seg.query(0,N)))

def op(a, b):
    return max(a, b)


class segmentTree:
    def __init__(self, n, op, init_value):
        dataLen = 1 << (n - 1).bit_length()
        self.data = [init_value] * (2 * dataLen)
        self.op = op
        self.length = dataLen

    def getIdx(self, left, right):
        idxs = []
        l = left
        r = right
        while True:
            idx = 1
            valueL = 0
            valueR = self.length - 1
            while l != valueL or valueR >= r:
                if l <= (valueR + valueL) // 2:
                    valueR -= (valueR - valueL + 1) // 2
                    idx *= 2
                else:
                    valueL += (valueR - valueL + 1) // 2
                    idx = idx * 2 + 1
            idxs.append(idx)
            if valueR == r - 1:
                break
            l = valueR + 1
        return idxs

    def get(self, n):
        return self.data[self.getIdx(n, n + 1)[0]]

    def set(self, n, value):
        if n < 0 or n >= self.length:
            return False
        idx1 = self.getIdx(n, n + 1)[0]
        self.data[idx1] = value
        while idx1 != 1:
            idx2 = idx1 ^ 1
            if idx1 > idx2:
                idx1, idx2 = idx2, idx1
            self.data[idx1 // 2] = self.op(self.data[idx1], self.data[idx2])
            idx1 //= 2
        return True

    def query(self, l, r):
        idxs = self.getIdx(l, r)
        ret = self.data[idxs[0]]
        for idx in idxs:
            ret = self.op(ret, self.data[idx])
        return ret


N, K = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(int(eval(input())))
N = 300000
seg = segmentTree(N, op, 0)
for i in A:
    l = min(N, max(0, i - K))
    r = max(0, min(N, i + K))
    v = seg.query(l, r + 1)
    seg.set(i, v + 1)
print((seg.query(0, N)))

def op(a, b):
    return max(a, b)


class segmentTree:
    def __init__(self, n, op, init_value):
        dataLen = 1 << (n - 1).bit_length()
        self.data = [init_value] * (2 * dataLen)
        self.op = op
        self.length = dataLen

    def getIdx(self, left, right):
        idxs = []
        l = left
        r = right
        while True:
            idx = 1
            valueL = 0
            valueR = self.length - 1
            while l != valueL or valueR >= r:
                if l <= (valueR + valueL) // 2:
                    valueR -= (valueR - valueL + 1) // 2
                    idx *= 2
                else:
                    valueL += (valueR - valueL + 1) // 2
                    idx = idx * 2 + 1
            idxs.append(idx)
            if valueR == r - 1:
                break
            l = valueR + 1
        return idxs

    def get(self, n):
        return self.data[n + self.length]

    def set(self, n, value):
        idx1 = n + self.length
        self.data[idx1] = value
        while idx1 != 1:
            idx2 = idx1 ^ 1
            if idx1 > idx2:
                idx1, idx2 = idx2, idx1
            self.data[idx1 // 2] = self.op(self.data[idx1], self.data[idx2])
            idx1 //= 2

    def query(self, l, r):
        idxs = self.getIdx(l, r)
        ret = self.data[idxs[0]]
        for idx in idxs:
            ret = self.op(ret, self.data[idx])
        return ret


N, K = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(int(eval(input())))
N = 300000
seg = segmentTree(N, op, 0)
for i in A:
    l = min(N, max(0, i - K))
    r = max(0, min(N, i + K))
    v = seg.query(l, r + 1)
    seg.set(i, v + 1)
print((seg.query(0, N)))

-        return self.data[self.getIdx(n, n + 1)[0]] +        return self.data[n + self.length] -        if n < 0 or n >= self.length: -            return False -        idx1 = self.getIdx(n, n + 1)[0] +        idx1 = n + self.length -        return True