Buggy python submission (verdict: Time Limit Exceeded):
a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[0]*a
c[0]=0
for i in range(1,a):
  c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
print(c[-1])

Fixed submission:
def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()

Buggy python submission (verdict: Time Limit Exceeded):
a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[0 for i in range(a)]
c[0]=0
for i in range(1,a):
  c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
print(c[-1])

Fixed submission:
def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()

Buggy python submission (verdict: Time Limit Exceeded):
a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[float("inf") for i in range(a)]
c[0]=0
for i in range(1,a):
  c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
print(c[-1])

Fixed submission:
def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()

Buggy python submission (verdict: Time Limit Exceeded):
a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[float("inf") for i in range(a)]
c[0]=0
for i in range(0,a):
  for j in range(1,aa+1):
    if i+j==a:
      break
    else:
      c[i+j]=min(c[i]+abs(b[i]-b[i+j]),c[i+j])
print(c[-1])

Fixed submission:
def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()

Buggy python submission (verdict: Time Limit Exceeded):
a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[0 for i in range(a)]
for i in range(1,a):
  for j in range(1,aa+1):
    if i-j<0:
      break
    elif j==1:
      c[i]=c[i-j]+abs(b[i]-b[i-j])
    elif c[i]<=c[i-j]:
      continue
    else:
      c[i]=min(c[i-j]+abs(b[i]-b[i-j]),c[i])
  
print(c[-1])

Fixed submission:
def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()

Buggy python submission (verdict: Time Limit Exceeded):
a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[0 for i in range(a)]
for i in range(1,a):
  for j in range(1,aa+1):
    if i-j<0:
      break
    elif j==1:
      c[i]=c[i-j]+abs(b[i]-b[i-j])
    else:
      c[i]=min(c[i-j]+abs(b[i]-b[i-j]),c[i])
  
print(c[-1])

Fixed submission:
def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()

Buggy python submission (verdict: Time Limit Exceeded):
a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[1000000007 for i in range(a)]
c[0]=0
for i in range(1,a):
  for j in range(1,aa+1):
    if i-j<0:
      break
    else:
      c[i]=min(c[i-j]+abs(b[i]-b[i-j]),c[i])
  
print(c[-1])

Fixed submission:
def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()