Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
	w[i], v[i] = map(int, input().split())

V = sum(v)
dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]
"""
for j in range(V + 1):
	dp[0][j] = 0
"""
dp[0][0] = 0
# dp[i][j]:i番目までの品物から価値がj以上になるよう選んだときの重さの総和の最小値
for i in range(N):
	for j in range(V + 1):
		# i+1番目を選ぶ場合
		if j - v[i] >= 0:
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
		# i+1番目を選ばない場合
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

# print(dp)

# dp[N][j]がW以下であるようなjの最大値が答えになる
ans = 0
for j in range(V + 1):
	if dp[N][j] <= W:
		ans = j

print(ans)


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
	dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
	if i > 1:
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
def cost(i):
	if i == 0:
		return 0
	elif i == 1:
		return abs(h[1] - h[0])
	else:
		return min(cost(i - 1) + abs(h[i] - h[i - 1]), cost(i - 2) + abs(h[i] - h[i - 2]))
print(cost(N - 1))


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
	dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
	if i > 1:
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
def cost(i):
	if i == 0:
		return 0
	else:
		tmp = float("inf")
		tmp = min(tmp, cost(i - 1) + abs(h[i] - h[i - 1]))
		if i > 1:
			tmp = min(tmp, cost(i - 2) + abs(h[i] - h[i - 2]))
		return tmp
N = int(input())
h = list(map(int, input().split()))
print(cost(N - 1))

Fixed submission:
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
	dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
	if i > 1:
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
def cost(i):
	if i <= 0:
		return 0
	else:
		tmp = float("inf")
		tmp = min(tmp, cost(i - 1) + abs(h[i] - h[i - 1]))
		tmp = min(tmp, cost(i - 2) + abs(h[i] - h[i - 2]))
		return tmp
N = int(input())
h = list(map(int, input().split()))
print(cost(N - 1))


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
	dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
	if i > 1:
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N):
	dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
	dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[N - 1])


Fixed submission:
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(1, N):
	dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
	if i > 1:
		dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[N - 1])