import sys



input = sys.stdin.buffer.readline





class SegmentTree:

    ele = 0

    func = max

    # SEG木は1-index

    # Aに関しては0-index



    def __init__(self, n):  # Aは0-idx

        self.n = n

        self.num = 2 ** ((self.n - 1).bit_length())

        self.SEG = [self.ele] * (2 * self.num)



    def search(self, idx):

        return self.SEG[idx + self.num]



    def initialize(self, A):

        for i in range(self.n):

            self.SEG[i + self.num] = A[i]

        for i in range(self.num - 1, 0, -1):

            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])



    # 1点更新

    def set(self, idx, val):

        idx += self.num

        self.SEG[idx] = val

        idx //= 2

        while idx:

            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])

            idx //= 2



    # 区間取得

    def query(self, left, right):

        # 開区間

        resleft = self.ele

        resright = self.ele

        left += self.num

        right += self.num

        while right - left > 0:

            if left % 2 == 1:

                resleft = self.func(resleft, self.SEG[left])

                left += 1

            if right % 2 == 1:

                right -= 1

                resright = self.func(resright, self.SEG[right])

            left //= 2

            right //= 2

        return self.func(resleft, resright)





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

ans = 0

ST = SegmentTree(3000001)

for _ in range(n):

    val = int(eval(input()))

    lower = val - k

    lower = max(lower, 0)

    upper = val + k

    upper = min(upper, 3000000)

    temp = ST.query(lower, upper + 1) + 1

    ST.set(val, temp)

    ans = max(ans, temp)

print(ans)

import sys





input = sys.stdin.buffer.readline



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

max_n = 300000

num = 2 ** ((max_n - 1).bit_length())

SEG = [0] * (2 * num)

func = max

ele = 0





def update(idx, val):

    idx += num

    SEG[idx] = val

    while idx > 0:

        idx //= 2

        SEG[idx] = func(SEG[2 * idx], SEG[2 * idx + 1])





def query(left, right):

    res_left = ele

    res_right = ele

    left += num

    right += num

    while right - left > 0:

        if left & 1:

            res_left = func(res_left, SEG[left])

            left += 1

        if right & 1:

            right -= 1

            res_right = func(SEG[right], res_right)

        left //= 2

        right //= 2

    return func(res_left, res_right)





for _ in range(n):

    val = int(eval(input()))

    temp = query(max(0, val - k), min(max_n + 1, val + k + 1))

    temp += 1

    update(val, temp)





print((SEG[1]))



import sys

input = sys.stdin.buffer.readline


class SegmentTree:
    ele = 0
    func = max
    # SEG木は1-index
    # Aに関しては0-index
    def __init__(self, n):  # Aは0-idx
        self.n = n
        self.num = 2 ** ((self.n - 1).bit_length())
        self.SEG = [self.ele] * (2 * self.num)

    def search(self, idx):
        return self.SEG[idx + self.num]

    def initialize(self, A):
        for i in range(self.n):
            self.SEG[i + self.num] = A[i]
        for i in range(self.num - 1, 0, -1):
            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])

    # 1点更新
    def set(self, idx, val):
        idx += self.num
        self.SEG[idx] = val
        idx //= 2
        while idx:
            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])
            idx //= 2

    # 区間取得
    def query(self, left, right):
        # 開区間
        resleft = self.ele
        resright = self.ele
        left += self.num
        right += self.num
        while right - left > 0:
            if left % 2 == 1:
                resleft = self.func(resleft, self.SEG[left])
                left += 1
            if right % 2 == 1:
                right -= 1
                resright = self.func(resright, self.SEG[right])
            left //= 2
            right //= 2
        return self.func(resleft, resright)


n, k = list(map(int, input().split()))
ans = 0
ST = SegmentTree(3000001)
for _ in range(n):
    val = int(eval(input()))
    lower = val - k
    lower = max(lower, 0)
    upper = val + k
    upper = min(upper, 3000000)
    temp = ST.query(lower, upper + 1) + 1
    ST.set(val, temp)
    ans = max(ans, temp)
print(ans)

import sys

input = sys.stdin.buffer.readline
n, k = list(map(int, input().split()))
max_n = 300000
num = 2 ** ((max_n - 1).bit_length())
SEG = [0] * (2 * num)
func = max
ele = 0


def update(idx, val):
    idx += num
    SEG[idx] = val
    while idx > 0:
        idx //= 2
        SEG[idx] = func(SEG[2 * idx], SEG[2 * idx + 1])


def query(left, right):
    res_left = ele
    res_right = ele
    left += num
    right += num
    while right - left > 0:
        if left & 1:
            res_left = func(res_left, SEG[left])
            left += 1
        if right & 1:
            right -= 1
            res_right = func(SEG[right], res_right)
        left //= 2
        right //= 2
    return func(res_left, res_right)


for _ in range(n):
    val = int(eval(input()))
    temp = query(max(0, val - k), min(max_n + 1, val + k + 1))
    temp += 1
    update(val, temp)
print((SEG[1]))

+n, k = list(map(int, input().split())) +max_n = 300000 +num = 2 ** ((max_n - 1).bit_length()) +SEG = [0] * (2 * num) +func = max +ele = 0 -class SegmentTree: -    ele = 0 -    func = max -    # SEG木は1-index -    # Aに関しては0-index -    def __init__(self, n):  # Aは0-idx -        self.n = n -        self.num = 2 ** ((self.n - 1).bit_length()) -        self.SEG = [self.ele] * (2 * self.num) - -    def search(self, idx): -        return self.SEG[idx + self.num] - -    def initialize(self, A): -        for i in range(self.n): -            self.SEG[i + self.num] = A[i] -        for i in range(self.num - 1, 0, -1): -            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1]) - -    # 1点更新 -    def set(self, idx, val): -        idx += self.num -        self.SEG[idx] = val +def update(idx, val): +    idx += num +    SEG[idx] = val +    while idx > 0: -        while idx: -            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1]) -            idx //= 2 - -    # 区間取得 -    def query(self, left, right): -        # 開区間 -        resleft = self.ele -        resright = self.ele -        left += self.num -        right += self.num -        while right - left > 0: -            if left % 2 == 1: -                resleft = self.func(resleft, self.SEG[left]) -                left += 1 -            if right % 2 == 1: -                right -= 1 -                resright = self.func(resright, self.SEG[right]) -            left //= 2 -            right //= 2 -        return self.func(resleft, resright) +        SEG[idx] = func(SEG[2 * idx], SEG[2 * idx + 1]) -n, k = list(map(int, input().split())) -ans = 0 -ST = SegmentTree(3000001) +def query(left, right): +    res_left = ele +    res_right = ele +    left += num +    right += num +    while right - left > 0: +        if left & 1: +            res_left = func(res_left, SEG[left]) +            left += 1 +        if right & 1: +            right -= 1 +            res_right = func(SEG[right], res_right) +        left //= 2 +        right //= 2 +    return func(res_left, res_right) + + -    lower = val - k -    lower = max(lower, 0) -    upper = val + k -    upper = min(upper, 3000000) -    temp = ST.query(lower, upper + 1) + 1 -    ST.set(val, temp) -    ans = max(ans, temp) -print(ans) +    temp = query(max(0, val - k), min(max_n + 1, val + k + 1)) +    temp += 1 +    update(val, temp) +print((SEG[1]))