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: #!/usr/bin/env python3
  import sys
  
  sys.setrecursionlimit(10**6)
  INF = 10**9 + 1  # sys.maxsize # float("inf")
  MOD = 10**9 + 7
  
  
  def debug(*x):
      print(*x, file=sys.stderr)
  
  
  def solve(N, K, AS):
      candidates = [[0]]
      for i in range(1, N):
          A = AS[i]
          new_candidates = []
          for c in candidates:
              if abs(AS[c[-1]] - A) <= K:
                  new_candidates.append(c[:])
                  c.append(i)
                  new_candidates.append(c)
                  break
              else:
                  new_candidates.append(c)
          else:
              new_candidates.append([i])
          candidates = new_candidates
          candidates.sort(key=len, reverse=True)
          # debug("candidates", candidates)
      return len(candidates[0])
  
  
  def main():
      # parse input
      N, K = map(int, input().split())
      AS = []
      for i in range(N):
          AS.append(int(input()))
  
      print(solve(N, K, AS))
  
  
  # tests
  T1 = """
  10 3
  1
  5
  4
  3
  8
  6
  9
  7
  2
  4
  """
  TEST_T1 = """
  >>> as_input(T1)
  >>> main()
  7
  """
  
  T2 = """
  6 2
  5
  7
  3
  3
  3
  3
  """
  TEST_T2 = """
  >>> as_input(T2)
  >>> main()
  5
  """
  
  
  def _test():
      import doctest
  
      doctest.testmod()
      g = globals()
      for k in sorted(g):
          if k.startswith("TEST_"):
              doctest.run_docstring_examples(g[k], g, name=k)
  
  
  def as_input(s):
      "use in test, use given string as input file"
      import io
  
      f = io.StringIO(s.strip())
      g = globals()
      g["input"] = lambda: bytes(f.readline(), "ascii")
      g["read"] = lambda: bytes(f.read(), "ascii")
  
  
  input = sys.stdin.buffer.readline
  read = sys.stdin.buffer.read
  
  if sys.argv[-1] == "-t":
      print("testing")
      _test()
      sys.exit()
  
  main()
  
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."}]