def segfunc(x, y): return max(x, y)



class SegmentTree:

    def __init__(self, arr):

        size = len(arr)

        n = 2 ** (size - 1).bit_length()

        self.n = n

        self.node = [0] * (2*n)

        for i in range(size):

            self.node[i+n-1] = arr[i]

        for i in reversed(list(range(n-2))):

            self.node[i] = segfunc(self.node[2*i+1], self.node[2*i+2])



    def update(self, i, x):

        i += self.n - 1

        self.node[i] = x

        while i > 0:

            i = (i - 1) // 2

            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2])



    def update(self, x, val):

        x += (self.n - 1)

        self.node[x] = val

        while x > 0:

            x = (x - 1) // 2

            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2])



    def query(self, a, b):

        res = 0

        l = self.n - 1 + a

        r = self.n - 1 + (b - 1)



        while l <= r:

            if l == r:

                res = segfunc(res, self.node[l])

                break



            if l % 2 == 0:

                res = segfunc(res, self.node[l])

            if r % 2 == 1:

                res = segfunc(res, self.node[r])

            l = l // 2

            r = r // 2 - 1



        return res



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

INF = 0

seg = SegmentTree([0] * 300000)

for i in range(N):

    a = int(eval(input()))

    tmp = seg.query(max(a - K, 0), min(a + K, 300000) + 1) + 1

    seg.update(a, tmp)

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

def segfunc(x, y): return max(x, y)

def update(i, x):

    i += MAX_N-1

    node[i] = x

    while i:

        i = (i-1)//2

        node[i] = segfunc(node[i*2+1], node[i*2+2])



def query(l, r):

    L = l + MAX_N

    R = r + MAX_N

    s = INF

    while L < R:

        if R & 1:

            R -= 1

            s = segfunc(s, node[R - 1])

        if L & 1:

            s = segfunc(s, node[L - 1])

            L += 1

        L >>= 1

        R >>= 1

    return s



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

MAX_N = 2**(300005).bit_length()

a = [int(eval(input())) for _ in range(N)]

node = [0] * (2 * MAX_N)

INF = 0

ans = 0



#for i in range(N):

#    update(i, a[i])



for i in a:

    tmp = query(max(i - K, 0), min(300005, i + K) + 1)

    update(i, tmp + 1)

    ans = max(ans, tmp + 1)

print(ans)

def segfunc(x, y):
    return max(x, y)


class SegmentTree:
    def __init__(self, arr):
        size = len(arr)
        n = 2 ** (size - 1).bit_length()
        self.n = n
        self.node = [0] * (2 * n)
        for i in range(size):
            self.node[i + n - 1] = arr[i]
        for i in reversed(list(range(n - 2))):
            self.node[i] = segfunc(self.node[2 * i + 1], self.node[2 * i + 2])

    def update(self, i, x):
        i += self.n - 1
        self.node[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2])

    def update(self, x, val):
        x += self.n - 1
        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2])

    def query(self, a, b):
        res = 0
        l = self.n - 1 + a
        r = self.n - 1 + (b - 1)
        while l <= r:
            if l == r:
                res = segfunc(res, self.node[l])
                break
            if l % 2 == 0:
                res = segfunc(res, self.node[l])
            if r % 2 == 1:
                res = segfunc(res, self.node[r])
            l = l // 2
            r = r // 2 - 1
        return res


N, K = list(map(int, input().split()))
INF = 0
seg = SegmentTree([0] * 300000)
for i in range(N):
    a = int(eval(input()))
    tmp = seg.query(max(a - K, 0), min(a + K, 300000) + 1) + 1
    seg.update(a, tmp)
print((seg.query(0, 300000)))

def segfunc(x, y):
    return max(x, y)


def update(i, x):
    i += MAX_N - 1
    node[i] = x
    while i:
        i = (i - 1) // 2
        node[i] = segfunc(node[i * 2 + 1], node[i * 2 + 2])


def query(l, r):
    L = l + MAX_N
    R = r + MAX_N
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = segfunc(s, node[R - 1])
        if L & 1:
            s = segfunc(s, node[L - 1])
            L += 1
        L >>= 1
        R >>= 1
    return s


N, K = list(map(int, input().split()))
MAX_N = 2 ** (300005).bit_length()
a = [int(eval(input())) for _ in range(N)]
node = [0] * (2 * MAX_N)
INF = 0
ans = 0
# for i in range(N):
#    update(i, a[i])
for i in a:
    tmp = query(max(i - K, 0), min(300005, i + K) + 1)
    update(i, tmp + 1)
    ans = max(ans, tmp + 1)
print(ans)

-class SegmentTree: -    def __init__(self, arr): -        size = len(arr) -        n = 2 ** (size - 1).bit_length() -        self.n = n -        self.node = [0] * (2 * n) -        for i in range(size): -            self.node[i + n - 1] = arr[i] -        for i in reversed(list(range(n - 2))): -            self.node[i] = segfunc(self.node[2 * i + 1], self.node[2 * i + 2]) +def update(i, x): +    i += MAX_N - 1 +    node[i] = x +    while i: +        i = (i - 1) // 2 +        node[i] = segfunc(node[i * 2 + 1], node[i * 2 + 2]) -    def update(self, i, x): -        i += self.n - 1 -        self.node[i] = x -        while i > 0: -            i = (i - 1) // 2 -            self.node[i] = segfunc(self.node[i * 2 + 1], self.node[i * 2 + 2]) -    def update(self, x, val): -        x += self.n - 1 -        self.node[x] = val -        while x > 0: -            x = (x - 1) // 2 -            self.node[x] = segfunc(self.node[2 * x + 1], self.node[2 * x + 2]) - -    def query(self, a, b): -        res = 0 -        l = self.n - 1 + a -        r = self.n - 1 + (b - 1) -        while l <= r: -            if l == r: -                res = segfunc(res, self.node[l]) -                break -            if l % 2 == 0: -                res = segfunc(res, self.node[l]) -            if r % 2 == 1: -                res = segfunc(res, self.node[r]) -            l = l // 2 -            r = r // 2 - 1 -        return res +def query(l, r): +    L = l + MAX_N +    R = r + MAX_N +    s = INF +    while L < R: +        if R & 1: +            R -= 1 +            s = segfunc(s, node[R - 1]) +        if L & 1: +            s = segfunc(s, node[L - 1]) +            L += 1 +        L >>= 1 +        R >>= 1 +    return s +MAX_N = 2 ** (300005).bit_length() +a = [int(eval(input())) for _ in range(N)] +node = [0] * (2 * MAX_N) -seg = SegmentTree([0] * 300000) -for i in range(N): -    a = int(eval(input())) -    tmp = seg.query(max(a - K, 0), min(a + K, 300000) + 1) + 1 -    seg.update(a, tmp) -print((seg.query(0, 300000))) +ans = 0 +# for i in range(N): +#    update(i, a[i]) +for i in a: +    tmp = query(max(i - K, 0), min(300005, i + K) + 1) +    update(i, tmp + 1) +    ans = max(ans, tmp + 1) +print(ans)