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: from functools import lru_cache
  
  
  @lru_cache(maxsize=40000)
  def subsolve(i):
      a = As[i]
      l = None
      r = None
      for j in range(i, 0, -1):
          if a - k <= As[j - 1] <= a and l == None:
              l = subsolve(j - 1) + 1
          if a < As[j - 1] <= a + k and r == None:
              r = subsolve(j - 1) + 1
          if l != None and r != None:
              break
      if l == None:
          l = 1
      if r == None:
          r = 1
      return max(l, r)
  
  
  def solve(n, k, xs):
      return max(subsolve(i) for i in range(n))
  
  
  if __name__ == "__main__":
      n, k = map(int, input().split())
      (*As,) = [int(input()) for _ in range(n)]
      print(solve(n, k, As))
  
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."}]