output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      A_1
      A_2
      :
      A_N
attempt: import sys
  
  input = lambda: sys.stdin.readline().rstrip()
  sys.setrecursionlimit(max(1000, 10**9))
  write = lambda x: sys.stdout.write(x + "\n")
  
  
  ### セグメント木
  class SegmentTree:
      def __init__(self, n, a=None):
          """初期化
          num : n以上の最小の2のべき乗
          """
          num = 1
          while num <= n:
              num *= 2
          self.num = num
          self.seg = [ninf] * (2 * self.num - 1)
          if a is not None:
              # O(n)で初期化
              assert len(a) == n
              for i in range(n):
                  self.seg[num - 1 + i] = a[i]
              for k in range(num - 2, -1, -1):
                  self.seg[k] = op(self.seg[2 * k + 1], self.seg[2 * k + 2])
  
      def update(self, i, x):
          """update(i,x):Aiをxに更新する"""
          k = i + (self.num - 1)
          self.seg[k] = x
          k = (k - 1) // 2
          while k >= 0:
              self.seg[k] = op(self.seg[2 * k + 1], self.seg[2 * k + 2])
              k = (k - 1) // 2
  
      def query(self, a, b):
          k = 0
          l = 0
          r = self.num
          q = [(k, l, r)]
          ans = ninf
          # 重なる区間を深さ優先探索
          while q:
              k, l, r = q.pop()
              if r <= a or b <= l:
                  pass
              elif a <= l and r <= b:
                  ans = op(ans, self.seg[k])
              else:
                  q.append((2 * k + 1, l, (l + r) // 2))
                  q.append((2 * k + 2, (l + r) // 2, r))
          return ans
  
      def find_right(self, a, b, x=None, f=None):
          """[a,b)で値がx以上のインデックスの最大
          存在しない場合-1を返す
          """
          if f is None:
              f = lambda y: y >= x
          k = 0
          l = 0
          r = self.num
          q = [(k, l, r, True)]  # 行きがけかどうか
          ans = -1
          while q:
              k, l, r, flg = q.pop()
              if flg:
                  if (
                      not f(self.seg[k]) or r <= a or b <= l
                  ):  # 条件を満たせない or 区間が重複しない
                      pass
                  elif k >= self.num - 1:  # 自身が葉
                      ans = max(ans, k - (self.num - 1))
                      return ans
                  else:
                      # 左への探索を予約
                      q.append((2 * k + 1, l, (l + r) // 2, False))
                      # 右への探索
                      q.append((2 * k + 2, (l + r) // 2, r, True))
              else:
                  if ans >= 0:
                      return ans
                  q.append((k, l, r, True))
          return ans
  
      def find_left(self, a, b, x=None, f=None):
          """[a,b)で値がx以上のインデックス(0,1,...,self.num-1)の最小
          条件を満たすものが存在しないとき、self.numを返す
          """
          if f is None:
              f = lambda y: y >= x
          k = 0
          l = 0
          r = self.num
          q = [(k, l, r, True)]  # 行きがけかどうか
          ans = self.num
          while q:
              k, l, r, flg = q.pop()
              if flg:
                  if (
                      not f(self.seg[k]) or r <= a or b <= l
                  ):  # x以上を満たせない or 区間が重複しない
                      continue
                  elif k >= self.num - 1:  # 自身が葉
                      ans = min(ans, k - (self.num - 1))
                      return ans
                  else:
                      # 右への探索を予約
                      q.append((2 * k + 2, (l + r) // 2, r, False))
                      # 左への探索
                      q.append((2 * k + 1, l, (l + r) // 2, True))
              else:
                  if ans < self.num:
                      return ans
                  q.append((k, l, r, True))
          return ans
  
      def query_index(self, a, b, k=0, l=0, r=None):
          """query(a,b,0,0,num):[a,b)の最大値
          最大値を与えるインデックスも返す
          """
          if r is None:
              r = self.num
          if r <= a or b <= l:
              return (ninf, None)
          elif a <= l and r <= b:
              return (self.seg[k], self._index(k))
          else:
              return op(
                  self.query_index(a, b, 2 * k + 1, l, (l + r) // 2),
                  self.query_index(a, b, 2 * k + 2, (l + r) // 2, r),
              )
  
      def _index(self, k):
          if k >= self.num:
              return k - (self.num - 1)
          else:
              if self.seg[2 * k + 1] >= self.seg[2 * k + 2]:
                  return self._index(2 * k + 1)
              else:
                  return self._index(2 * k + 2)
  
  
  ninf = -(10**9)
  op = max
  n, k = list(map(int, input().split()))
  a = [int(input()) for _ in range(n)]
  size = max(a) + 2
  sg = SegmentTree(size)
  for i in range(n):
      v = a[i]
      m, M = max(0, v - k), min(v + k, size - 1)
      val = sg.query(m, M + 1)
      if val < 0:
          val = 0
      sg.update(v, val + 1)
  ans = sg.query(0, size)
  print(ans)
  
problem_description: Statement
  
  You are given a sequence A_1, A_2, ..., A_N and an integer K.
  
  Print the maximum possible length of a sequence B that satisfies the following
  conditions:
  
    * B is a (not necessarily continuous) subsequence of A.
    * For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
samples: [{"input": "10 3\n    1\n    5\n    4\n    3\n    8\n    6\n    9\n    7\n    2\n    4", "output": "7\n    \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n  * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n  * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]