Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03161 (python)

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

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

Fixed submission:
N = int(input())
a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
	a[i], b[i], c[i] = map(int, input().split())
dp = [[0] * 3 for _ in range(N)]
dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
a, b, c = [map(int, input().split()) for _ in range(N)]
dp = [0, 0, 0] * N
dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))
Problem p03164 (python)

Fixed submission:
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)

Buggy 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())

dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
	for j in range(W + 1):
		if j - w[i] >= 0:
			dp[i + 1][j] = dp[i][j - w[i]] + v[i]
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(dp[N][W])
Problem p03196 (python)

Fixed submission:
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N, P = map(int, input().split())
f = Counter(prime_factorize(P))

ans = 1
for k, v in f.items():
    if v >= N:
        ans *= k ** (v//N)
print(ans)

Buggy submission (verdict: Runtime Error):
from sympy import factorint

N, P = map(int, input().split())
f = factorint(P)

ans = 1
for k, v in f.items():
    if v >= N:
        ans *= k * (v//N)
print(ans)
Problem p03211 (python)

Fixed submission:
S = input()
ans = 753
for i in range(len(S) - 2):
	tmp = abs(int(S[i]) * 100 + int(S[i + 1]) * 10 + int(S[i + 2]) - 753)
	if tmp < ans:
		ans = tmp
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
ans = 753
for i in range(len(S) - 2):
	tmp = S[i] * 100 + S[i + 1] * 10 + S[i + 2]
	if abs(tmp - 753) < ans:
		ans = tmp
print(ans)
Problem p03228 (python)

Fixed submission:
A, B, K = map(int, input().split())
for i in range(K):
	if i % 2 == 0:
		# takahashi
		if A % 2 == 1:
			A -= 1
		A, B = A // 2, B + A // 2
	else:
		# aoki
		if B % 2 == 1:
			B -= 1
		A, B = A + B // 2, B // 2
print(A, B)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input())
for i in range(K):
	if i % 2 == 0:
		# takahashi
		if A % 2 == 1:
			A -= 1
		A, B = A // 2, B + A // 2
	else:
		# aoki
		if B % 2 == 1:
			B -= 1
		A, B = A + B // 2, B // 2
print(A, B)
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 0
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 1
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    if ind < K:
        print(S[ind])
    else:
        print("1")

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] != "1":
    print(S[0])
else:
    ind = 1
    while S[ind] == "1" and ind < len(S) - 1:
        ind += 1
    print(S[ind])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
if set(S) == "1":
    print(1)
elif S[0] == "1" and K > 1:
    ind = 1
    while S[ind] == "1":
        ind += 1
    print(S[ind])
else:
    print(S[0])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] == "1" and K > 1:
    ind = 1
    while S[ind] == "1":
        ind += 1
    print(S[ind])
else:
    print(S[0])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] == "1":
    ind = 1
    while S[ind] == "1":
        ind += 1
    print(S[ind])
else:
    print(S[0])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
if S[0] == "1":
    print(S[1])
else:
    print(S[0])
Problem p03355 (python)

Fixed submission:
from heapq import heappush, heappop

s = input()
K = int(input())

min_s = sorted(list(set(s)))

res = [min(s)]
q = []
x = 0

while len(set(q)) < K:
    min_index = [n for n, v in enumerate(s) if v == min_s[x]]
    for m in min_index:
        for i in range(1, 6):
            if m+i <= len(s):
                q.append(s[m:m+i])
    x += 1

ans = sorted(list(set(q)))[K-1]

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
        ans = list(set(ans))
    else:
        c = key.pop(0)
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(min(5, len(s) - i - 1)):
                queue.append(s[i:i+j+1])

print(ans[K-1])

Buggy submission (verdict: Runtime Error):
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
        ans = list(set(ans))
    else:
        c = key.pop(0)
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(len(s) - i - 1):
                queue.append(s[i:i+j+1])

print(ans[K-1])

Buggy submission (verdict: Runtime Error):
from collections import Counter

s = input()
K = int(input())
c = Counter(s)

key = sorted(c.keys())
ans = []
queue = []

while (len(ans) < K):
    if queue:
        queue = sorted(list(set(queue)))
        res = queue.pop(0)
        ans.append(res)
    else:
        c = key.pop(0)
        queue.append(c)
        ind = [i for i in range(len(s)) if s[i] == c]
        for i in ind:
            for j in range(1, len(s) - i - 1):
                queue.append(s[i:i+j+1])

print(ans[K-1])
Problem p03415 (python)

Fixed submission:
x, y, z = input(), input(), input()
print(x[0] + y[1] + z[2])

Buggy submission (verdict: Runtime Error):
x, y, z = input() * 3
print(x[0] + y[1] + z[2])
Problem p03485 (python)

Fixed submission:
import math
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(math.ceil((a + b) / 2))

Buggy submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print(math.ceil((a + b) / x))
Problem p03544 (python)

Fixed submission:
N = int(input())
L = [0] * 87  # 制約から
L[0] = 2
L[1] = 1
if N >= 2:
	for i in range(2, N + 1):
		L[i] = L[i - 1] + L[i - 2]
print(L[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [0] * 86  # 86は制約から
L[0] = 2
L[1] = 1
if N >= 2:
	for i in range(2, N + 1):
		L[i] = L[i - 1] + L[i - 2]
print(L[N])
Problem p03559 (python)

Fixed submission:
from bisect import bisect_right, bisect_left

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0

for bi in range(N):
    ai_max = bisect_left(A, B[bi])
    ci_min = bisect_right(C, B[bi])
    ans += (ai_max) * (N - ci_min)

print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0

for ai in range(N):
    bi = bisect_left(B, A[ai])
    ci = bisect_left(C, B[bi])
    ans += (N-bi)*(N-ci)

print(ans)
Problem p03563 (python)

Fixed submission:
r, g = eval("int(input())," * 2)
print(2 * g - r)

Buggy submission (verdict: Runtime Error):
r, g = map(int, input().split())
print(2 * g - r)
Problem p03574 (python)

Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
for i in range(H):
	for j in range(W):
		if S[i][j] == ".":
			cnt = 0
			if i != 0:
				cnt += S[i - 1][max(0, j - 1): min(j + 1, W - 1) + 1].count("#")
			cnt += S[i][max(0, j - 1): min(j + 1, W - 1) + 1].count("#")
			if i != H - 1:
				cnt += S[i + 1][max(0, j - 1): min(j + 1, W - 1) + 1].count("#")
			S[i][j] = str(cnt)
for x in range(H):
	print("".join(S[x]))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ans = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"
        else:
            if 0 < i and i < H-1:
                li = [i-1, i, i+1]
            elif i == 0:
                li = [i, i+1]
            else:
                li = [i-1, i]
            if 0 < j and j < W-1:
                lj = [j-1, j, j+1]
            elif j == 0:
                lj = [j, j+1]
            else:
                lj = [j-1, j]
            ans[i][j] = str(sum([S[lii][ljj]=="#" for lii in li for ljj in lj]))

for i in range(H):
    s = "".join(ans[i])
    print(s)
Problem p03599 (python)

Fixed submission:
A, B, C, D, E, F =  map(int, input().split())
M = 0
for i in range(F // 100 // A + 1):
	for j in range((F - 100 * A * i) // 100 // B + 1):
		w = 100 * A * i + 100 * B * j
		if w == 0:
			break
		for k in range((F - w) // C + 1):
			for l in range((F - w - C * k) // D + 1):
				s = C * k + D * l
				if E >= 100 * s / w and 100 * s / w >= M:
					M = 100 * s / w
					X = [w + s, s]
print(X[0], X[1])

Buggy submission (verdict: Runtime Error):
A, B, C, D, E, F =  map(int, input().split())
M = 0
for i in range(F // 100 // A + 1):
	for j in range((F - 100 * A * i) // 100 // B + 1):
		w = 100 * A * i + 100 * B * j
		if w == 0:
			break
		for k in range((F - w) // C + 1):
			for l in range((F - w - C * k) // D + 1):
				s = C * k + D * l
				if E >= 100 * s / w and 100 * s / w > M:
					M = 100 * s / w
					X = [w + s, s]
print(X[0], X[1])
Problem p03607 (python)

Fixed submission:
from collections import Counter

N = int(input())
A = [int(input()) for _ in range(N)]
c = Counter(A).values()

print(len([i for i in c if i % 2 == 1]))

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
A = [int(input()) for _ in range(N)]
c = Counter(A)
print(len([i for i in c if c.values(i) % 2 == 1]))
Problem p03633 (python)

Fixed submission:
import fractions
N = int(input())
T = [int(input()) for _ in range(N)]
ans = T[0]
for i in range(N - 1):
	ans = ans * T[i + 1] // fractions.gcd(ans, T[i + 1])
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
N = int(input())
T = list(map(int, input().split()))
ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.grid(ans, T[i])
print(ans)
Problem p03644 (python)

Fixed submission:
N = int(input())
for i in range(N, 0, -1):
	a = bin(i)
	if a[2] == "1":
		if len(a) == 3:
			print(1)
			exit()
		elif not "1" in a[3:]:
			print(i)
			exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
ans_list = [2**i for i in range(7)]
ai = 0
while (ans_list[ai] <= N):
    ai += 1

print(ans_list[max(0, ai-1)])

Buggy submission (verdict: Runtime Error):
N = int(input())
ans_list = [2**i for i in range(7)]
ai = 0
while (ans_list[ai] <= N):
    ai += 1

print(ans_list[ai-1])
Problem p03665 (python)

Fixed submission:
N, P = map(int, input().split())
A = list(map(int, input().split()))
a = [i%2 for i in A]
zero = a.count(0)
one = a.count(1)

if one == 0 and P == 1:
    print(0)
else:
    print( (2**zero) * (2**(max(0, one-1))) )

Buggy submission (verdict: Runtime Error):
N, P = map(int, input().split())
A = [i%2 for i in list(map(int, input().split))]
zero = A.count(0)
one = A.count(1)

print( (2**zero) * (2**(max(0, one-1))) )
Problem p03719 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a <= c and c <= b:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int(input().split()))
if a <= c and c <= b:
	print("Yes")
else:
	print("No")
Problem p03738 (python)

Fixed submission:
A, B = eval("int(input())," * 2)
if A > B:
	print("GREATER")
elif A < B:
	print("LESS")
else:
	print("EQUAL")

Buggy submission (verdict: Runtime Error):
A, B = eval("int(input())" * 2)
if A > B:
	print("GREATER")
elif A < B:
	print("LESS")
else:
	print("EQUAL")

Buggy submission (verdict: Runtime Error):
A, B = eval("int(input()," * 2)
if A > B:
	print("GREATER")
elif A < B:
	print("LESS")
else:
	print("EQUAL")
Problem p03944 (python)

Fixed submission:
W, H, N = map(int, input().split())
z = [list(map(int, input().split())) for _ in range(N)]
one, two, three, four = [0], [W], [0], [H]
for i in range(N):
	if z[i][2] == 1:
		one.append(z[i][0])
	elif z[i][2] == 2:
		two.append(z[i][0])
	elif z[i][2] == 3:
		three.append(z[i][1])
	else:
		four.append(z[i][1])
w = W - max(one) - (W - min(two))
h = H - max(three) - (H - min(four))
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)

Buggy submission (verdict: Runtime Error):
W, H, N = map(int, input().split())
z = [list(map(int, input().split())) for _ in range(N)]
one, two, three, four = [], [], [], []
for i in range(N):
	if z[i][2] == 1:
		one.append(z[i][0])
	elif z[i][2] == 2:
		two.append(z[i][0])
	elif z[i][2] == 3:
		three.append(z[i][1])
	else:
		four.append(z[i][1])
w = W - max(one) - (W - min(two))
h = H - max(three) - (H - min(four))
if w > 0 and h > 0:
	print(w * h)
else:
	print(0)
Problem p03967 (python)

Fixed submission:
s = input()
g_cnt, p_cnt = 0, 0
ans = 0
for si in s:
    if si == "g":
        if p_cnt < g_cnt:
            p_cnt += 1
            ans += 1
        else:
            g_cnt += 1
    else:
        if p_cnt < g_cnt:
            p_cnt += 1
        else:
            g_cnt += 1
            ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
g_cnt, p_cnt = 0, 0
ans = 0
for si in s:
    if si = "g":
        if p_cnt < g_cnt:
            p_cnt += 1
            ans += 1
        else:
            g_cnt += 1
            ans -= 1
    else:
        g_cnt += 1
        ans += 1
print(ans)
Problem p03993 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    j = a[i] - 1
    if i < j and a[j] - 1 == i:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    j = a[i] - 1
    if i < j and a[j] - 1 == i:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
*a, = map(int, input().split())
ans = 0

for i in range(N):
	if i = a.index(a[i]):
		ans += 1
print(ans)
Problem p02855 (python)

Fixed submission:
def main():
    H, W, K = [int(c) for c in input().split()]
    cake = [list(input()) for _ in range(H)]
    ichigo = [0]*H
    result = [[] for _ in range(H)]
    last_one = -1
    for i in range(H):
        for j in range(W):
            if cake[i][j] == "#":
                ichigo[i]+=1
    ichigo_no = 0
    for i in range(H):
        if ichigo[i] == 0:
            continue
        ichigo_no+=1
        for j in range(W):
            if cake[i][j] == ".":
                result[i].append(ichigo_no)
            else:
                result[i].append(ichigo_no)
                ichigo[i] -= 1
                if ichigo[i] != 0:
                    ichigo_no += 1

    for i in range(1,H):
        if len(result[i]) == 0 and len(result[i-1]) != 0:
            result[i] = result[i-1]
    for i in reversed(range(H-1)):
        if len(result[i]) == 0 and len(result[i+1]) != 0:
            result[i] = result[i+1]
    for i in range(H):
        for j in range(W-1):
            print(result[i][j], end=" ")
        print(result[i][-1])

main()

Buggy submission (verdict: Runtime Error):
def main():
    H, W, K = [int(c) for c in input().split()]
    cake = [list(input()) for _ in range(H)]
    ichigo = [0]*H
    result = [[] for _ in range(H)]
    last_one = -1
    for i in range(H):
        for j in range(W):
            if cake[i][j] == "#":
                ichigo[i]+=1
    ichigo_no = 0
    for i in range(H):
        if ichigo[i] == 0:
            continue
        ichigo_no+=1
        for j in range(W):
            if cake[i][j] == ".":
                result[i].append(ichigo_no)
            else:
                result[i].append(ichigo_no)
                ichigo[i] -= 1
                if ichigo[i] != 0:
                    ichigo_no += 1

    for i in range(H-1):
        if len(result[i]) == 0 and len(result[i+1]) != 0:
            result[i] = result[i+1]
    for i in reversed(range(1,H)):
        if len(result[i]) == 0 and len(result[i-1]) != 0:
            result[i] = result[i-1]
    for i in range(H):
        for j in range(W-1):
            print(result[i][j], end=" ")
        print(result[i][-1])

main()
Problem p03047 (python)

Fixed submission:
def main():
    A, B = [int(i) for i in input().split()]
    print(A - B + 1)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    A = int(input())
    B = int(input())
    print(A - B + 1)
if __name__ == "__main__":
    main()
Problem p03061 (python)

Fixed submission:

def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    fore = [0]*N
    back=[0]*N
    fore[0] = A[0]
    back[-1] = A[-1]
    for i in range(1, N):
        fore[i] = gcd(fore[i-1], A[i])
    for i in reversed(list(range(0, N-1))):
        back[i] = gcd(back[i+1], A[i])
    maximum = 0
    for i in range(N):
        f = fore[i-1] if i != 0 else 0
        b = back[i+1] if i != N-1 else 0
        m = gcd(f, b)
        maximum = max(m, maximum)
    print(maximum)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
main()

Buggy submission (verdict: Runtime Error):
import math
def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    fore = [0]*N
    back=[0]*N
    fore[0] = A[0]
    back[-1] = A[-1]
    for i in range(1, N):
        fore[i] = math.gcd(fore[i-1], A[i])
    for i in reversed(list(range(0, N-1))):
        back[i] = math.gcd(back[i+1], A[i])
    maximum = 0
    for i in range(N):
        f = fore[i-1] if i != 0 else 0
        b = back[i+1] if i != N-1 else 0
        m = math.gcd(f, b)
        maximum = max(m, maximum)
    print(maximum)
main()
Problem p03161 (python)

Fixed submission:
def a():
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        dp[i] = min([dp[k] + abs(h[k] - h[i]) for k in range(max(i - K, 0), i)])
    print(dp[N-1])

if __name__ == "__main__":
    a()

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * int(1e10)
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        minimum = 1e10
        stop = K + 1
        if i - K < 0:
            stop = i + 1
        for k in range(1, stop):
            cost = dp[i - k] + abs(h[i] - h[i-k])
            if cost < minimum:
                minimum = cost
        # print(ary)
        dp[i] = minimum
    print(dp[N-1])

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * int(10)
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        minimum = 1e10
        stop = K + 1
        if i - K < 0:
            stop = i + 1
        for k in range(1, stop):
            cost = dp[i - k] + abs(h[i] - h[i-k])
            if cost < minimum:
                minimum = cost
        # print(ary)
        dp[i] = minimum
    print(dp[N-1])

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * int(10)
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        minimum = 1e10
        stop = K + 1
        if i - K < 0:
            stop = i + 1
        for k in range(1, stop):
            cost = dp[i - k] + abs(h[i] - h[i-k])
            if cost < minimum:
                minimum = cost
        # print(ary)
        print(dp)
        print("--")
        dp[i] = minimum
    print(dp[N-1])