Buggy python submission (verdict: Runtime Error):
import pdb
import sys

def solve(a,N,K):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        for j in xrange(1,K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j],abs(a[i]-a[i+j])+dp[i])
            else:
                break
    return dp[N-1]
    
if __name__=='__main__':
    N,K = map(int,raw_input().split())
    a = map(int,raw_input().split())
    print solve(a,N,K)


Fixed submission:
import pdb
import sys

def solve(a,N):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        if i+1 < N:
            dp[i+1] = min(dp[i+1],abs(a[i]-a[i+1])+dp[i])
        if i+2<N:
            dp[i+2] = min(dp[i+2],abs(a[i]-a[i+2])+dp[i])
        
    return dp[N-1]
    
if __name__=='__main__':
    N = int(raw_input())
    a = map(int,raw_input().split())
    print solve(a,N)

Buggy python submission (verdict: Runtime Error):
import pdb
import sys

def solve(a,N,K):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        for j in xrange(1,K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j],abs(a[i]-a[i+j])+dp[i])
            else:
                break
    return dp[N-1]
    
if __name__=='__main__':
    N,K = map(int,raw_input().split())
    a = map(int,raw_input().split())
    print solve(a,N,K)


Fixed submission:
import pdb
import sys

def solve(a,N):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        if i+1 < N:
            dp[i+1] = min(dp[i+1],abs(a[i]-a[i+1])+dp[i])
        if i+2<N:
            dp[i+2] = min(dp[i+2],abs(a[i]-a[i+2])+dp[i])
        
    return dp[N-1]
    
if __name__=='__main__':
    N = int(raw_input())
    a = map(int,raw_input().split())
    print solve(a,N)

Buggy python submission (verdict: Runtime Error):
import pdb
import sys

def solve(a,N,K):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        for j in xrange(1,K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j],abs(a[i]-a[i+j])+dp[i])
            else:
                break
    return dp[N-1]
    
if __name__=='__main__':
    N,K = map(int,raw_input().split())
    a = map(int,raw_input().split())
    print solve(a,N,K)


Fixed submission:
import pdb
import sys

def solve(a,N):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        if i+1 < N:
            dp[i+1] = min(dp[i+1],abs(a[i]-a[i+1])+dp[i])
        if i+2<N:
            dp[i+2] = min(dp[i+2],abs(a[i]-a[i+2])+dp[i])
        
    return dp[N-1]
    
if __name__=='__main__':
    N = int(raw_input())
    a = map(int,raw_input().split())
    print solve(a,N)

Buggy python submission (verdict: Runtime Error):
def jump_cost(value1, value2):
  return abs(value1 - value2)

n = int(input())
stones = [int(i) for i in input().split()]
cost = [float("inf")] * n
cost[0] = 0

for index in range(len(stones) - 1):
  cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
  if index + 2 < n:
    cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

return cost[-1]

Fixed submission:
def jump_cost(value1, value2):
  return abs(value1 - value2)

def stone_jump(n, stones):
  cost = [float("inf")] * n
  cost[0] = 0

  for index in range(len(stones) - 1):
    cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
    if index + 2 < n:
      cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

  print(cost[-1])
  return cost[-1]

n = int(input())
stones = [int(i) for i in input().split()]
stone_jump(n, stones)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
stones = [int(i) for i in input().split()]

jumps = {}
lowest_cost = None

stack = []
if n == 2:
  stack.append((0, 1, 0))
elif n > 2:
  stack.append((0, 2, 0))
  stack.append((0, 1, 0))

while stack:
  current_index, next_index, cost = stack.pop()
  next_path = (current_index, next_index)
  if next_path not in jumps:
    jumps[next_path] = abs(stones[current_index] - stones[next_index])

  new_cost = cost + jumps[next_path]
  if next_index + 1 == n:
    if lowest_cost is None or new_cost < lowest_cost:
      lowest_cost = new_cost
  elif next_index + 2 == n:
    stack.append((next_index, next_index + 1, new_cost))
  else:
    stack.append((next_index, next_index + 2, new_cost))
    stack.append((next_index, next_index + 1, new_cost))

print(lowest_cost)

Fixed submission:
def jump_cost(value1, value2):
  return abs(value1 - value2)

def stone_jump(n, stones):
  cost = [float("inf")] * n
  cost[0] = 0

  for index in range(len(stones) - 1):
    cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
    if index + 2 < n:
      cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

  print(cost[-1])
  return cost[-1]

n = int(input())
stones = [int(i) for i in input().split()]
stone_jump(n, stones)

Buggy python submission (verdict: Runtime Error):
  jumps = {}
  lowest_cost = None

  stack = []
  if n == 2:
    stack.append((0, 1, 0))
  elif n > 2:
    stack.append((0, 2, 0))
    stack.append((0, 1, 0))

  while stack:
    current_index, next_index, cost = stack.pop()
    next_path = (current_index, next_index)
    if next_path not in jumps:
      jumps[next_path] = abs(stones[current_index] - stones[next_index])

    new_cost = cost + jumps[next_path]
    if next_index + 1 == n:
      if lowest_cost is None or new_cost < lowest_cost:
        lowest_cost = new_cost
    elif next_index + 2 == n:
      stack.append((next_index, next_index + 1, new_cost))
    else:
      stack.append((next_index, next_index + 2, new_cost))
      stack.append((next_index, next_index + 1, new_cost))

  return lowest_cost

Fixed submission:
def jump_cost(value1, value2):
  return abs(value1 - value2)

def stone_jump(n, stones):
  cost = [float("inf")] * n
  cost[0] = 0

  for index in range(len(stones) - 1):
    cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
    if index + 2 < n:
      cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

  print(cost[-1])
  return cost[-1]

n = int(input())
stones = [int(i) for i in input().split()]
stone_jump(n, stones)

Buggy python submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(100000)

@lru_cache(maxsize = None)

def dp(n):
	if n == 0:
		return 0
	if n == 1:
		return abs(l[0] - l[1])
	return min(dp(n - 1) + abs(l[n] - l[n - 1]), dp(n - 2) + abs(l[n] - l[n - 2]))

n = int(input())
l = [int(i) for i in input().split(" ")]

print(dp(n - 1)) 

Fixed submission:
n = int(input())
l = [int(i) for i in input().split(" ")]
dp = [0 for i in range(n + 1)]
dp[1] = abs(l[0] - l[1])
for i in range(2, n):
	dp[i] = min(dp[i - 1] + abs(l[i] - l[i - 1]), dp[i - 2] + abs(l[i] - l[i - 2]))
print(dp[n - 1])

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

N = int(input())
a = list(map(int, input().split()))

@lru_cache(maxsize=None)
def f(n):
	if n == 0: return 0
	if n == 1: return abs(a[0] - a[1])
	return min(f(n - 1) + abs(a[n - 1] - a[n]), f(n - 2) + abs(a[n - 2] - a[n]))

print(f(N - 1))


Fixed submission:
from functools import lru_cache
from sys import setrecursionlimit

setrecursionlimit(900010)

N = int(input())
a = list(map(int, input().split()))

@lru_cache(maxsize=None)
def f(n):
	if n == 0: return 0
	if n == 1: return abs(a[0] - a[1])
	return min(f(n - 1) + abs(a[n - 1] - a[n]), f(n - 2) + abs(a[n - 2] - a[n]))

print(f(N - 1))

Buggy python submission (verdict: Runtime Error):
INF=int(1e6)

N=int(input())
heights=[int(x) for x in input().split()]
dp=[INF]*N
if(N==1):
  print(dp[0])
  exit()

dp[1]=heights[1]-heights[0]

for i in range(2,N):
	dp[i]=min(dp[i-1],dp[i-2])

    
print(dp[N])


Fixed submission:
INF=int(1e6)

N=int(input())
heights=[int(x) for x in input().split()]
# print('heights: ',heights)
dp=[INF]*N
# print(dp)
if(N==1):
  print(dp[0])
  exit()

dp[0]=0
dp[1]=abs(heights[1]-heights[0])

for i in range(2,N):
	dp[i]= min(abs(heights[i]- heights[i-1])+ dp[i-1],abs(heights[i]- heights[i-2])+ dp[i-2])


# print('dp: ',dp)
print(dp[N-1])

#30->60->60->50
#30   30  30  40

Buggy python submission (verdict: Runtime Error):
INF=int(1e6)

N=int(input())
heights=[int(x) for x in input().split()]
dp=[INF]*N
if(N==1):
  print(dp[0])
  return

dp[1]=heights[1]-heights[0]

for i in range(2,N):
	dp[i]=min(dp[i-1],dp[i-2])

    
print(dp[N])

Fixed submission:
INF=int(1e6)

N=int(input())
heights=[int(x) for x in input().split()]
# print('heights: ',heights)
dp=[INF]*N
# print(dp)
if(N==1):
  print(dp[0])
  exit()

dp[0]=0
dp[1]=abs(heights[1]-heights[0])

for i in range(2,N):
	dp[i]= min(abs(heights[i]- heights[i-1])+ dp[i-1],abs(heights[i]- heights[i-2])+ dp[i-2])


# print('dp: ',dp)
print(dp[N-1])

#30->60->60->50
#30   30  30  40