Buggy python submission (verdict: Runtime Error):
N, W = list(map(int, input().split()))
w = list()
v = list()

dp = list()

for i in range (0, N):
	inp = list(map(int, input().split()))

	w.append(inp[0])
	v.append(inp[1])	

for i in range (0, N + 1):
	dp.append([0] * ( W + 1 ))

for i in range(0, N):
	for j in range(1, W+1):
		if(j >= w[i]):
			dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j])
		else:
			dp[i+1][j] = dp[i][j]

print(dp[N][W])

Fixed submission:
# DP practice
# https://atcoder.jp/contests/dp/tasks/dp_a

# 入力方法としてはこれが手軽
N = int(input())
h = list(map(int, input().split()))

dp = list()

# N = 0, 1 の時の処理も必要。だが省く
dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))


print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
# DP practice
# https://atcoder.jp/contests/dp/tasks/dp_b

# 入力方法としてはこれが手軽
N, K = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = list()

# N = 0, 1 の時の処理も必要。だが省く
dp.append(0)

# dp_a を改造した方法で単純にやってみる。
for i in range(1, N):

	min_cost_sum = 99999999
	for k in range(1, K+1):
		if(i-k) < 0:
			break

		tmp = dp[i-k] + abs(h[i] - h[i-k])
		if(tmp < min_cost_sum):
			min_cost_sum = tmp

	dp.append(min_cost_sum)


print(dp[N-1])

# Failure
# 1.初期値を dp[0] = h[0] の方が正しいと思ってしまった
#   → dpの意味を誤解
#
# 2.abs をつけていなかった
#   → コストの全てのパターン意識していなかった。正の場合しか考えていない
#

Fixed submission:
# DP practice
# https://atcoder.jp/contests/dp/tasks/dp_a

# 入力方法としてはこれが手軽
N = int(input())
h = list(map(int, input().split()))

dp = list()

# N = 0, 1 の時の処理も必要。だが省く
dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

for i in range(2, N):
	dp.append(min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1])))


print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
def minjump(li , lir):
    #print(li,lir)
    if tuple(li) in lir.keys():
        return lir[tuple(li)]
    else:
        if(len(li)<2):
            return 0 
        elif(len(li) == 2):
            lir[tuple(li)] = abs(li[0]-li[1])
            return lir[tuple(li)]   
        else:
            val1 = abs(li[0]-li[1])+minjump(li[1:],lir)
            val2 = abs(li[0]-li[2])+minjump(li[2:],lir)
            lir[tuple(li)] = min(val1,val2)
            #print(li,lir[tuple(li)])
            return lir[tuple(li)] 

t= int(input())
num = list(map(int,input().split()))
listi = dict()
print(minjump(num,listi))


Fixed submission:
n  = int(input())
k = 2
num = list(map(int,input().split()))
numval = list()
for data in range(n):
    numval.append(1000000000)
numval[0] = 0
i = 0
if(n<k):
    k = n-1
for i in range(0,n):
    for data in range(1,k+1):
        if(i+data)>=n:
            break
        numval[i+data] = min(numval[i+data],numval[i]+abs(num[i]-num[i+data]))
    i += 1
print(numval[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
vis[2]=abs(arr[0]-arr[1])
def c(i):
  if i in vis:
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  return vis[i]
c(n)
print(vis[n])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
vis[2]=abs(arr[0]-arr[1])
def c(i):
  if i in vis:
    #print(vis)
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  #print(i, x, y, vis)
  return vis[i]
c(n)
print(vis[n])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
if n < 2:
  print(0)
  exit
vis[2]=abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
  exit
def c(i):
  if i in vis:
    #print(vis)
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  #print(i, x, y, vis)
  return vis[i]
c(n)
print(vis[n])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
if n < 2:
  print(0)
  exit
vis[2]=abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
  exit
def c(i):
  if i in vis:
    #print(vis)
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  #print(i, x, y, vis)
  return vis[i]
c(n)
print(vis[n-1])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
def count(x):
    if x < 0:
      return 0
    if x in vis:
      return vis[x]
    else:
      vis[x]=min(abs(arr[x]-arr[x-1])+count(x-1),abs(arr[x]-arr[x-2])+count(x-2))
    return vis[x]
  
vis={}
vis[0] = 0
if n < 2:
  print(0)
elif n == 2:
  print(abs(arr[0]-arr[1]))
else:
    vis[1] = abs(arr[0]-arr[1])
    print(count(n-1))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1] = 0
if n < 2:
  print(0)
  exit
if n == 2:
  print(abs(arr[0]-arr[1]))
  exit
vis[2] = abs(arr[0]-arr[1])
def count(x):
    if x < 0:
      return 0
    if x in vis:
      return vis[x]
    else:
      vis[x]=min(abs(arr[x-1]-arr[x-2])+count(x-1),abs(arr[x-1]-arr[x-3])+count(x-2))
    return vis[x]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1] = 0
if n < 2:
  print(0)
  exit
if n == 2:
  print(abs(arr[0]-arr[1]))
  exit
vis[2] = abs(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
      return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
  exit
if n == 2:
  print(min(arr[0]-arr[1]))
  exit
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
  return
if n == 2:
  print(min(arr[0]-arr[1]))
  return
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
  return
if n == 2:
  print(min(arr[0]-arr[1]))
  return
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
  	if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
  	if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
  	if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n in vis or n < 0:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  return 0
if n == 2:
  return min(arr[0]-arr[1])
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n in vis or n < 0:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  print(vis[0])
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  print(vis[0])
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[i-1])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  print(vis[0])
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  return 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(2, n+1):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-1]
    vis[i+1] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(2, n+1):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-1]
    vis[i+1] = min(step_1, step_2)
   
print(vis[i+1])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(2, n+1):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-1]
    vis[i+1] = min(step_1, step_2)
   
print(vis[n])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[n])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n+1):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  return 0
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  return vis[2]
for i in range(3, n+1):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])

for i in range(3, n+1):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])

for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3])+vis[i-2]
    vis[n] = min(step_1, step_2)
    print(vis)
print(vis[n])

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
def count(n):
  	n = n-1
  	if n in vis:
      return vis[n]
    step_1 = abs(arr[n]-arr[n-1])+count(n-1)
    step_2 = abs(arr[n]-arr[n-2])+count(n-2)
    vis[n] = min(step_1, step_2)
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    if n==2:
        vis[n]=abs(arr[n-1]-arr[n-2])+count(n-1)
    if n>=3:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),(abs(arr[n-1]-arr[n-3])+count(n-2)))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    if n==2:
        vis[n]=abs(arr[n-1]-arr[n-2])+count(n-1)
    if n>=3:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    if n==2:
        vis[n]=(abs(arr[n-1]-arr[n-2])+count(n-1))
    if n>=3:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
print(arr)
vis={}
vis[0] = 0
vis[1] = 0
def count(n):
    if n in vis:
        return vis[n]
    if n == 2:
        vis[n]=(abs(arr[n-1]-arr[n-2])+count(n-1))
    else:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy python submission (verdict: Runtime Error):
INF=1000000000
def getans(i):
    if i>=(n-1):
        dp[n-1]= 0
        return dp[n-1]
    if dp[i]!=-1:
        return dp[i]
    if i==(n-2):
        dp[i]=abs(h[i]-h[i+1])
        return dp[i]
    else:
        dp[i]=min(h[i]-h[i+1]+getans(i+1),h[i]-h[i+2]+getans(i+2))
        return dp[i]


n=int(input())
dp=[-1]*n
h=list(map(int,input().split()))
ans=getans(0)
print(ans)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    if i+2<n:
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
INF=1000000000
def getans(i):
    if i>=(n-1):
        dp[n-1]= 0
        return dp[n-1]
    if dp[i]!=-1:
        return dp[i]
    if i==(n-2):
        dp[i]=abs(h[i]-h[i+1])
        return dp[i]
    else:
        dp[i]=min(abs(h[i]-h[i+1])+getans(i+1),abs(h[i]-h[i+2])+getans(i+2))
        return dp[i]


n=int(input())
dp=[-1]*n
h=list(map(int,input().split()))
ans=getans(0)
print(ans)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    if i+2<n:
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[-1])