Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
inf = float('inf')
dp = [inf for _ in range(n)]

# メモ化再帰（一度計算した結果はメモしておく）
def rec(i):
  # 値が既に更新されていたらそのまま返す（計算し直さない）
  if dp[i] != inf:
    return dp[i]
  if i==0:
    return 0
  res = inf
  res = min(res, rec(i-1) + abs(h[i]-h[i-1]))
  if i > 1:
    res = min(res, rec(i-2) + abs(h[i]-h[i-2]))
  #print('dp[{}] = {}'.format(i, res))
  dp[i] = res
  return res

ans = rec(n-1)
print(ans)

Fixed submission:
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), 
             dp[i-2] + abs(h[i-2]-h[i]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
inf = float('inf')
dp = [inf for _ in range(n)]

# メモ化再帰（一度計算した結果はメモしておく）
def rec(i):
  # 値が既に更新されていたらそのまま返す（計算し直さない）
  if dp[i] < inf: return dp[i]
  if i==0: return 0
  res = inf
  res = min(res, rec(i-1) + abs(h[i]-h[i-1]))
  if i > 1: res = min(res, rec(i-2) + abs(h[i]-h[i-2]))
  dp[i] = res
  return res

ans = rec(n-1)
print(ans)

Fixed submission:
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), 
             dp[i-2] + abs(h[i-2]-h[i]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
inf = float('inf')
dp = [inf for _ in range(n)]
# メモ化再帰（一度計算した結果はメモしておく）
def rec(i):
  # 値が既に更新されていたらそのまま返す（計算し直さない）
  if dp[i] < inf: return dp[i]
  if i==0: return 0
  res = inf
  res = min(res, rec(i-1) + abs(h[i]-h[i-1]))
  if i>1: res = min(res, rec(i-2) + abs(h[i]-h[i-2]))
  dp[i] = res
  return res
ans = rec(n-1)
print(ans)


Fixed submission:
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), 
             dp[i-2] + abs(h[i-2]-h[i]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
inf = float('inf')
dp = [inf for _ in range(n)]
# メモ化再帰（一度計算した結果はメモしておく）
def rec(i):
  # 値が既に更新されていたらそのまま返す（計算し直さない）
  if dp[i] < inf: return dp[i]
  if i==0: return 0
  res = inf
  res = min(res, rec(i-1) + abs(h[i]-h[i-1]))
  if i>1: res = min(res, rec(i-2) + abs(h[i]-h[i-2]))
  dp[i] = res
  return res
ans = rec (n-1)
print(ans)

Fixed submission:
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), 
             dp[i-2] + abs(h[i-2]-h[i]))
print(dp[n-1])