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

Fixed submission:
N = int(input())
S, T = map(str, input().split())

ST = ''

for i in range(N):
  ST += S[i]
  ST += T[i]

print(ST)

Buggy submission (verdict: Runtime Error):
N = int(input())
S, T = map(str, input().split())
T = str(input())

ST = ''

for i in range(N):
  ST += S[i]
  ST += T[i]

print(ST)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())
T = str(input())

ST = ''

for i in range(N):
  ST += S[i]
  ST += T[i]

print(ST)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())
T = str(input())

for i in range(N):
	ST[i]   = S[i]
  	ST[i+1] = T[i]

Buggy submission (verdict: Runtime Error):
N = int(input())
S = str(input())
T = str(input())

for i in range(N)
	ST[i]   = S[i]
  	ST[i+1] = T[i]
Problem p02811 (python)

Fixed submission:
k,x=(int(a) for a in input().split())
if(x<=k*500):
    print("Yes")
else:
   print("No")

Buggy submission (verdict: Runtime Error):
K=int(input())
X=int(input())
if(X<=K*500):
    print("Yes")
else:
   print("No")
Problem p02887 (python)

Fixed submission:
N = int(input())

S = list(input())

                
i = 0
while i != len(S) - 1:
    if S[i] == S[i+1]:
        S.pop(i)
    else:
        i += 1
print(len(S))

Buggy submission (verdict: Runtime Error):
N = int(input())

S = list(input())

def independent(S):
    if len(S) == 1:
        return True
    else:
        for i in range(len(S) - 1):
            if S[i] == S[i+1]:
                flag = 0
                break
            else:
                flag = 1
        if flag == 1:
            return True
        else:
            return False
                
i = 0
while independent(S) == False:
    if i == len(S) - 1:
        i = 0
    if S[i] == S[i+1]:
        S.pop(i)
    i += 1

print(len(S))
Problem p02898 (python)

Fixed submission:
N,K = map(int,input().split())

lis = []
count = 0

lis = list(map(int,input().split()))
  
for height in lis:
  if height >= K:
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())

lis = []
count = 0

for _ in range(int(input())):
  lis.append(input())
  
for height in lis:
  if height >= K:
    count += 1
    
print(count)
Problem p02899 (python)

Fixed submission:

N = int(input())
lis = []
lis = list(map(int,input().split()))
first = [0]*N

for i in range(N):
    num = lis[i] - 1
    first[num] = i

for i in range(N):
    print(first[i]+1,end=' ')
print()

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
lis = list(map(lambda x: -int(x),input().split()))

import heapq
heapq.heapify(lis)
for _ in range(M):
    tmp = -heapq.heappop(lis)
    tmp //= 2
    heapq.heappush(lis,-tmp)

print(-sum(lis))

Buggy submission (verdict: Runtime Error):
N = int(input())

lis = []

lis = list(map(int,input().split()))

first = []*N

for i in range(N):
  num = lis[i]
  first[num] = i
  
for i in range(N):
  print(for _ in first)

Buggy submission (verdict: Runtime Error):
N = int(input())

lis = []

lis = list(map(int,input().split()))

first = []*N

for i in range(N):
  num = lis[i]
  first[num] = i
  
for i in range(N):
  print(first[i],end=' ')

Buggy submission (verdict: Runtime Error):
N = int(input())

lis = []

lis = list(map(int,input().split()))

first = []*N

for i in range(N):
  num = lis[i] - 1
  first[num] = i + 1
  
for i in range(N):
  print(first[i],end=' ')

Buggy submission (verdict: Runtime Error):
N = int(input())

lis = []

lis = list(map(int,input().split()))

first = []*N

for i in range(N):
  num = lis[i]
  first[num] = i + 1
  
for i in range(N):
  print(first[i],end=' ')

Buggy submission (verdict: Runtime Error):
N = int(input())

lis = []

lis = list(map(int,input().split()))

first = []

for i in range(N):
  num = lis[i]
  first[num] = i + 1
  
for i in range(N):
  print(first[i],end=' ')

Buggy submission (verdict: Runtime Error):
N = int(input())

lis = []

lis = list(map(int,input().split()))

first = []

for i in range(N):
  first[lis[i]] = i + 1
  
for i in range(N):
  print(first[i],end=' ')
Problem p02910 (python)

Fixed submission:
S = input()
lis = list(S)
count = 0

for i in range(len(lis)):
    if i % 2 == 0:
        if lis[i] == 'R':
            count += 1
    if i % 2 != 0:
        if lis[i] == 'L':
            count += 1

    if lis[i] == 'U' or lis[i] == 'D':
        count += 1

if count == len(lis):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
lis = list(S)


for i in range(len(lis)):
    if i % 2 == 0:
        if lis[i] == 'R' or lis[i] == 'U' or lis[i] == 'D':
            flag_o = 1
        else:
            flag_o = 0
            break
    if i % 2 != 0:
        if lis[i] == 'L' or lis[i] == 'U' or lis[i] == 'D':
            flag_e = 1
        else:
            flag_e = 0
            break
        
if flag_o == 1 and flag_e == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
lis = list(S)

for i in range(len(lis)):
    if i % 2 == 0:
        if lis[i] == 'R' or lis[i] == 'U' or lis[i] == 'D':
            flag_o = 1
        else:
            flag_o = 0
            break
    if i % 2 != 0:
        if lis[i] == 'L' or lis[i] == 'U' or lis[i] == 'D':
            flag_e = 1
        else:
            flag_e = 0
            break
        
if flag_o == 1 and flag_e == 1:
    print('Yes')
else:
    print('No')
Problem p02911 (python)

Fixed submission:
N,K,Q = map(int,input().split())

lis = []
for _ in range(Q):
    lis.append(int(input()))

point = [K] * N

for i in range(Q):
    num = lis[i]
    point[num-1] += 1

for j in range(N):
    point[j] -= Q



for i in range(N):
    if point[i] > 0:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
N,K,Q = map(int,input().split())

lis = []
point = []

for i in range(N+1):
    point[i] = K

for x in range(int(input())):
    lis.append(input())

for i in lis:
    for j in range(N+1):
        if i == j :
            point[j] += 1
        else:
            point[i] -= 1

for i in range(N+1):
    if point[i] >= 1:
        print("Yes")
    else:
        print("No")
Problem p02971 (python)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
B = [ [0] * 2 for i in range(N)]

for i in range(N):
    B[i][0] = A[i]
    B[i][1] = i

B.sort(reverse=True)
for i in range(N):
    if B[0][1] == i:
        print(B[1][0])
    else:
        print(B[0][0])

Buggy submission (verdict: Runtime Error):
import copy



N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
   # B = copy.deepcopy(A)
    tmp = A[i]
    a[i] = 0
    ans = max(A)
    a[i] = tmp
    print(ans)
Problem p03145 (python)

Fixed submission:
a,b,c = [int(x) for x in input().split()]
s = int(a * b / 2)
print(s)

Buggy submission (verdict: Runtime Error):
(a, b, c)=list(int, input().split())
s=a*b/2
print(s)
Problem p03206 (python)

Fixed submission:
day={
    25:'Christmas',
    24:'Christmas Eve',
    23:'Christmas Eve Eve',
    22:'Christmas Eve Eve Eve'
}

a = int(input())
print(day[a])

Buggy submission (verdict: Runtime Error):
n,k = input().split(' ')
n = int(n)
k = int(k)
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
diffs = []
for i in range(n-k+1):
    diffs.append(h[i+k] - h[i])
print(min(diffs))
Problem p03219 (python)

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

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(int(a+b/2))
Problem p02755 (python)

Fixed submission:
import sys
import math

read = sys.stdin.readline
S = read()

a, b = map(int, S.split())

fin = False
for i in range(1000+1):
    if a == math.floor(i * 0.08):
        if b == math.floor(i * 0.1):
            print(i)
            fin = True
            break
if not fin:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys
import math

read = ys.std.readline
S = read()

a, b = map(int, S.split())

for i in range(1000+1):
    if A == math.ceil(i * 0.08):
        if B == math.ceil(i * 0.1):
            print(i)
            return
print(-1)
Problem p02818 (python)

Fixed submission:
a, b, k = map(int, input().split())

print(str(max(0, a-k))+' '+str(max(0, min(b, a+b-k))))

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())

print(max(0, a-k)+' '+max(0, a+b-k))
Problem p02846 (python)

Fixed submission:
def main():
    t = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    diff_0 = a[0]-b[0]
    diff_1 = a[1]-b[1]

    if diff_0*diff_1 > 0:
        return 0
    
    d_one_iter = diff_0*t[0]+diff_1*t[1]

    if diff_0*d_one_iter > 0:
        return 0
    if diff_0*d_one_iter == 0:
        return 'infinity'
    
    if abs(diff_0*t[0])%abs(d_one_iter) == 0:
        return 2*abs(diff_0*t[0])//abs(d_one_iter)
    else:
        return 2*(abs(diff_0*t[0])//abs(d_one_iter))+1

if __name__ == "__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def main():
	t = map(int, input().split())
	a = map(int, input().split())
	b = map(int, input().split())
	
	d_0_a = a[0]*t[0]
	d_1_a = a[1]*t[1]
	d_0_b = b[0]*t[0]
	d_1_b = b[1]*t[1]
	
	d_ave_a = d_0_a+d_1_a
	d_ave_b = d_0_b+d_1_b
	
	if d_ave_a == d_ave_b:
		return 'infinity'
	
	diff_0 = d_0_a - d_0_b
	diff_1 = d_1_a - d_1_b
	diff_ave = d_ave_a - d_ave_b
	
	if diff_0*diff_1 > 0:
		return 0
		
	diff_diff_0 = diff_ave + diff_0
	diff_diff_1 = diff_ave + diff_1
	
	if diff_0*diff_ave < 0:
		return -diff_diff_0//diff_ave + 1
	else:
		return -diff_diff_1//diff_ave + 1
	
	
if __name__ == '__main__':
	print(main())
Problem p02900 (python)

Fixed submission:
from math import sqrt, ceil

def main():

    ab = input().split(' ')
    a = int(ab[0])
    b = int(ab[1])

    tmp = b
    if a<b:
        tmp = a
        a = b
        b = tmp

    while b != 0:
        tmp = b
        b = a%b
        a = tmp

    count = 1

    if a == 1:
        return count

    if a%2 == 0:
        count += 1
        while a%2 == 0:
            a //= 2
        if a == 1:
            return count
    
    i = 3
    while i*i <= a:
        if a%i == 0:
            count += 1
            while a%i == 0:
                a //= i
            if a == 1:
                return count
        i += 2
        
    return count+1

if __name__ == "__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
from math import sqrt, ceil

ab = input().split(' ')
a = int(ab[0])
b = int(ab[1])

tmp = b
if a<b:
	tmp = a
	a = b
	b = tmp

while b != 0:
	tmp = b
	b = a%b
	a = tmp

count = 1

if a == 1:
	return count

if a%2 == 0:
    count += 1
    while a%2 == 0:
        a //= 2

if a == 1:
	return count

while i*i <= a:
    if a%i == 0:
        count += 1
        while a%i == 0:
            a //= i
        if a == 1:
            break
    
return count

if __name__ == "__main__":
    print(main())
Problem p02818 (python)

Fixed submission:
#coding:utf-8
 
 
def main():
    list1  = list(map(int, input().split(' '))) 
    a, b, k = list1
  
    if a > k:
        a = a - k
      
    elif a + b >= k:
        b = b - (k - a)
        a = 0
        
    else:
        a = 0
        b = 0
        
    print(a, b)
  
    return 0
 
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def main():
    
    takahashi_cookie, aoki_cookie, action_count = map(int, input().split(' '))

    if action_count < takahashi_cookie:
        takahashi_result = takahashi_cookie - action_count
        aoki_result = aoki_result
        
    elif action_count <= (takahashi_cookie + aoki_cookie):
        takahashi_result = 0
        aoki_result = aoki_cookie - (action_count - takahashi_cookie)
        
    else:
        takahashi_result = 0
        aoki_result = 0
        
    print(takahashi_result, aoki_result)

    return 0
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def main():
    
    takahashi_cookie, aoki_cookie, action_count = map(int, input().split(' '))

    if action_count < takahashi_cookie:
        takahashi_result = takahashi_cookie - action_count
        aoki_result = aoki_result
    elif action_count <= (takahashi_cookie + aoki_cookie):
        takahashi_result = 0
        aoki_result = aoki_cookie - (action_count - takahashi_cookie)
    else:
        takahashi_result = 0
        aoki_result = 0
        
    print(takahashi_result, aoki_result)

    return 0
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def main():
    
    takahashi_cookie, aoki_cookie, action_count = map(int, input().split(' '))

    if action_count >= (takahashi_cookie + aoki_cookie):
        takahashi_result = 0
        aoki_result = 0
    elif action_count >= takahashi_cookie:
        takahashi_result = 0
        aoki_result = aoki_cookie - (action_count - takahashi_cookie)
    elif action_count < takahashi_cookie:
        takahashi_result = takahashi_cookie - action_count
        aoki_result = aoki_result
        
    print(takahashi_result, aoki_result)

    return 0
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# coding: utf-8


def main():
    
    takahashi_cookie, aoki_cookie, action_count = map(int, input().split(' '))

    if action_count > takahashi_cookie:
        takahashi_result = 0
        aoki_result = aoki_cookie - (action_count - takahashi_cookie)
    elif action_count < takahashi_cookie:
        takahashi_result = takahashi_cookie - action_count
        aoki_result = aoki_result
    elif action_count >= (takahashi_cookie + aoki_cookie):
        takahashi_result = 0
        aoki_result = 0
        
    print(takahashi_result, aoki_result)

    return 0
    

if __name__ == '__main__':
    main()
Problem p04012 (python)

Fixed submission:
# coding: utf-8
import sys


def main(argv=sys.argv):

    char_list = input()

    char_set = set(char_list)

    for char_ in char_set:

        if char_list.count(char_) % 2 != 0:

            print('No')

            return 0

    print('Yes')

    return 0


if __name__ == '__main__':
    sys.exit(main())

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys


def main(argv=sys.argv):

    char_list = input()

    char_set = set(char_list)

    for char in char_set:

        if char_list.count(char) % 2 != 0:

            print('No')

            return -1

    print('Yes')

    return 0


if __name__ == '__main__':
    sys.exit(main())
Problem p04029 (python)

Fixed submission:
# coding: utf-8
import sys


def main(argv=sys.argv):
  
  n = int(input())
  
  candy_count = 0

  if n == 1:
    candy_count = 1
  else:
    candy_count = (1 + n) * n // 2
    
  print(candy_count)
  
  return 0


if __name__ == '__main__':
  sys.exit(main())

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys
import numpy as np
import itertools


def main(argv=sys.argv):
  
    packs = list(map(int, input().split(' ')))
    packs = sorted(packs)
    if packs[2] - packs[1] - packs[0] == 0:
        print('Yes')
    else:
        print('No')
  
    return 0


if __name__ == '__main__':
    sys.exit(main())
Problem p04030 (python)

Fixed submission:
# coding: utf-8
import sys


def main(argv=sys.argv):
  
    inputs_ = list(input())

    string_ = []

    for input_ in inputs_:

        if input_ == 'B':

            if not string_ == []:
              
                string_.pop(-1)

        else:

            string_.append(input_)

    print(''.join(string_))

    return 0


if __name__ == '__main__':
    sys.exit(main())

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys


def main(argv=sys.argv):

  inputs_ = list(input())

    string_ = []

    for input_ in inputs_:

        if input_ == 'B':

            if not string_ == []:
              
                string_.pop(-1)

        else:

            string_.append(input_)

    print(''.join(string_))

    return 0


if __name__ == '__main__':
    sys.exit(main())
Problem p02812 (python)

Fixed submission:
N = int(input())
K = list(str(input()))
count=0


for i in range(N):  
  if K[i-2] == "A":
    if K[i-1] == "B":
      if K[i] == "C":
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = list(str(input()))
count=0


for i in range(N):  
  if K[i] == "A":
    if K[i+1] == "B":
      if K[i+2] == "C":
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = list(str(input()))
count=0


for i in range(N):
  if K[i-1] == "A":
    if K[i] == "B":
      if K[i+1] == "C":
        count += 1

print(count)
Problem p03238 (python)

Fixed submission:
n = input()

if n is'1':
  print("Hello World")
elif n is '2':
  a = int(input())
  b = int(input())
  print(a + b)

Buggy submission (verdict: Runtime Error):
n, t = map(int, input().split())

a = []

for i in range(n):
  cost, time = map(int, input().split())
  if time <= t:
    a.append(cost)

if len(a) is 0:
  print("TLE")
else:
  a.sort()
  print(a[0])
Problem p03239 (python)

Fixed submission:
n, t = map(int, input().split())

a = []

for i in range(n):
  cost, time = map(int, input().split())
  if time <= t:
    a.append(cost)

if len(a) is 0:
  print("TLE")
else:
  a.sort()
  print(a[0])

Buggy submission (verdict: Runtime Error):
n, t = map(int, input().split())

a = []

for i in range(n):
  cost, time = map(int, input().split())
  if time <= t:
    a.append(cost)

a.sort()
print(a[0])
Problem p02786 (python)

Fixed submission:
import sys
from functools import lru_cache
sys.setrecursionlimit(20000)


class Dp:

    def __init__(self, size):
        self.size = size

    @lru_cache(maxsize=None)
    def calc(self, n):
        if n == 1:
            return 1
        return self.calc(n//2) * 2 + 1


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(20000)


class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(20000)


class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10000)


class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**20)


class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
class Dp:

    def __init__(self, size):
        self.size = size
        self.array = [0] * (size+1)

    def calc(self, n):
        if n == 1:
            return 1
        if self.array[n] != 0:
            return self.array[n]
        self.array[n] = self.calc(n//2) * 2 + 1
        return self.array[n]


def main():
    h = int(input())
    dp = Dp(h)
    result = dp.calc(h)
    print(result)


if __name__ == "__main__":
    main()
Problem p02837 (python)

Fixed submission:
import sys
input = sys.stdin.readline


class Human:

    def __init__(self, statements):
        self.statements = statements

    def is_honest(self, honest_list):
        for x, y in self.statements:
            if y:
                if x not in honest_list:
                    return False
            else:
                if x in honest_list:
                    return False
        return True


class Humans:

    def __init__(self):
        self.humans = [None]

    def add(self, human: Human):
        self.humans.append(human)

    def is_all_honest(self, honest_list):
        for i in honest_list:
            if not self.humans[i].is_honest(honest_list):
                return False
        return True


def main():
    n = int(input())
    humans = Humans()
    for _ in range(n):
        a = int(input())
        xy = [tuple(map(int, input().split())) for _ in range(a)]
        humans.add(Human(xy))
    max_honest = 0
    for bit in range(2**n):
        honest_list = []
        for i in range(n):
            if (bit >> i) & 1:
                honest_list.append(i+1)  # 1ずれるため補正
        if humans.is_all_honest(honest_list):
            max_honest = max(max_honest, len(honest_list))
    print(max_honest)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from typing import List, Tuple
import sys
input = sys.stdin.readline


class Human:

    def __init__(self, statements: List[Tuple[int, int]]):
        self.statements = statements

    def is_honest(self, honest_list: List[int]):
        for x, y in self.statements:
            if y:
                if x not in honest_list:
                    return False
            else:
                if x in honest_list:
                    return False
        return True


class Humans:

    def __init__(self):
        self.humans = [None]

    def add(self, human: Human):
        self.humans.append(human)

    def is_all_honest(self, honest_list: List[int]):
        for i in honest_list:
            if not self.humans[i].is_honest(honest_list):
                return False
        return True


def main():
    n = int(input())
    humans = Humans()
    for _ in range(n):
        a = int(input())
        xy = [tuple(map(int, input().split())) for _ in range(a)]
        humans.add(Human(xy))
    max_honest = 0
    for bit in range(2**n):
        honest_list = []
        for i in range(n):
            if (bit >> i) & 1:
                honest_list.append(i+1)  # 1ずれるため補正
        if humans.is_all_honest(honest_list):
            max_honest = max(max_honest, len(honest_list))
    print(max_honest)


if __name__ == "__main__":
    main()
Problem p03161 (python)

Fixed submission:
import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] + [float("inf")] * (n-1)
    for i in range(1, n):
        for j in range(max(0, i-k), i):
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
    
    print(dp[-1])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    c = [0] + [abs(h[1] - h[0])]
    for i in range(2, n):
        min_step = 10 ** 4
        num = i if i <= k else k
        for j in range(num):
            step = abs(h[i] - h[i-j]) + c[i-j]
            if step < min_step:
                min_step = step
        c.append(min_step)
    print(c.pop())


if __name__ == "__main__":
    main()