output_description: Print the minimum possible total cost incurred.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      h_1 h_2 \ldots h_N
attempt: import math
  
  
  class Graph(object):
      def __init__(self, v):
          self.v = v
          self.visited = [False for i in range(v)]
          self.adj = [[] for i in range(v)]
          self.parent = [-1 for i in range(v)]
          self.distance = [0 for i in range(v)]
  
      def AddEdge(self, a, b):
          self.adj[a].append(b)
          self.adj[b].append(a)
  
      def BFS(self, start):
          Q = [start]
          self.visited[start] = True
          while len(Q) > 0:
  
              cur = Q.pop(0)
              for child in self.adj[cur]:
                  if self.visited[child] == False:
                      self.visited[child] = True
                      self.distance[child] = self.distance[cur] + 1
                      self.parent[child] = cur
                      Q.append(child)
  
      def CycleDetection_Using_BFS(self, start):
          Q = [start]
          self.visited[start] = True
          while len(Q) > 0:
  
              cur = Q.pop(0)
              for child in self.adj[cur]:
                  if self.visited[child] == False:
                      self.visited[child] = True
                      self.distance[child] = self.distance[cur] + 1
                      self.parent[child] = cur
                      Q.append(child)
                  else:
                      if self.parent[cur] != child:
                          return True
  
          return False
  
  
  NK = list(map(int, input().split(" ")))
  n, k = NK[0], NK[1]
  h = list(map(int, input().split(" ")))
  dp = [math.inf] * n
  for i in reversed(range(n)):
      m = math.inf
      for j in range(1, k + 1):
          Move = i + j
          if Move <= n - 1:
              m = min(m, dp[Move] + abs(h[i] - h[Move]))
      dp[i] = m if m != math.inf else 0
  print(dp[0])
  
problem_description: Statement
  
  There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
  the height of Stone i is h_i.
  
  There is a frog who is initially on Stone 1. He will repeat the following
  action some number of times to reach Stone N:
  
    * If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.
  
  Find the minimum possible total cost incurred before the frog reaches Stone N.
samples: [{"input": "5 3\n    10 30 40 50 20", "output": "30\n    \n\nIf we follow the path 1 \u2192 2 \u2192 5, the total cost incurred would be |10 - 30| +\n|30 - 20| = 30.\n\n* * *"}, {"input": "3 1\n    10 20 10", "output": "20\n    \n\nIf we follow the path 1 \u2192 2 \u2192 3, the total cost incurred would be |10 - 20| +\n|20 - 10| = 20.\n\n* * *"}, {"input": "2 100\n    10 10", "output": "0\n    \n\nIf we follow the path 1 \u2192 2, the total cost incurred would be |10 - 10| = 0.\n\n* * *"}, {"input": "10 4\n    40 10 20 70 80 10 20 70 80 60", "output": "40\n    \n\nIf we follow the path 1 \u2192 4 \u2192 8 \u2192 10, the total cost incurred would be |40 -\n70| + |70 - 70| + |70 - 60| = 40."}]