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

Fixed submission:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a, b, k = inpm()
ta = a - k
ao = b
if(ta < 0):
    ao = b + ta
    ta = 0
if(ao < 0):
    ao = 0
print(str(ta) + ' ' + str(ao))

Buggy submission (verdict: Runtime Error):
a, b, k = inpm()
ta = a - k
ao = b
if(ta < 0):
    ao = b - ta
    ta = 0
if(ao < 0):
    ao = 0
print(str(ta) + ' ' + str(ao))
Problem p02921 (python)

Fixed submission:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

al = input()
bl = input()
ans = 0
for i in range(0, 3):
    if(al[i] == bl[i]):
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

al = inpl()
bl = intp()
ans = 0
for i in range(0, 3):
    if(al[i] == bl[i]):
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

al = inpl()
bl = intp()
ans = 0
for i in range(0, 3):
    if(al[i] == bl[i]):
        ans++
print(ans)
Problem p02922 (python)

Fixed submission:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a, b = inpm()
tmp = a
if(b == 1):
    print(0)
else:
    ans = 1
    while(b > tmp):
        tmp += a - 1
        ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a, b = inpm()
tmp = a
if(b == 1):
    print(0)
else:
ans = 1
    while(b > tmp):
        tmp += a - 1
        ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a, b = inpm()
tmp = a
if(b == 1):
    print(0)
    return
ans = 1
while(b > tmp):
    tmp += a - 1
    ans += 1
print(ans)
Problem p02536 (python)

Fixed submission:
class UnionFind:
    from typing import List, Set

    def __init__(self, n):
        self.n = n
        self.parent = [-1] * n

    def merge(self, x, y) -> int:
        x = self.leader(x)
        y = self.leader(y)

        if x == y:
            return 0

        if self.parent[x] > self.parent[y]:
            x, y = y, x

        self.parent[x] += self.parent[y]
        self.parent[y] = x

        return self.parent[x]

    def same(self, x, y) -> bool:
        return self.leader(x) == self.leader(y)

    def leader(self, x) -> int:
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.leader(self.parent[x])
            return self.parent[x]

    def size(self, x) -> int:
        return -self.parent[self.leader(x)]

    def groups(self) -> List[Set[int]]:
        groups = dict()

        for i in range(self.n):
            p = self.leader(i)
            if not groups.get(p):
                groups[p] = set()
            groups[p].add(i)

        return list(groups.values())


def main():
    N, M = map(int, input().split())

    uf = UnionFind(N)

    for _ in range(M):
        # UnionFindを0スタートで実装しているので、入力から1引きます
        A, B = map(lambda x: int(x) - 1, input().split())  
        uf.merge(A, B)  # AとBをmergeします。union, uniteとも呼ばれます。

    print(len(uf.groups()) - 1)


if __name__ == '__main__':
    main()

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

roads=[]

for _ in range(m):
  a,b=map(int, input().split())
  if a<b:
  	roads.append([a,b].sort())
  else:
    roads.append([b,a].sort())
  
group=[i for i in range(n)]

group2=[]

while group2!=group:
  group2=group
  for road in roads:
    group[road[1]-1]=group[road[0]-1]

counter=1
for i in range(n-1):
  if group[i]!=group[i+1]:
    counter+=1

print(counter-1)

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

roads=[]

for _ in range(m):
  a,b=map(int, input().split())
  roads.append([a,b].sort())
  
group=[i for i in range(n)]

group2=[]

while group2!=group:
  group2=group
  for road in roads:
    group[road[1]-1]=group[road[0]-1]

counter=1
for i in range(n-1):
  if group[i]!=group[i+1]:
    counter+=1
    
print(counter-1)

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

roads=[]

for _ in range(m):
  a,b=map(int, input().split())
  roads.append([a,b].sort())
  
group=[i for i in range(n)]

group2=[]

while group2!=group:
  group2=group
  for road in roads:
    group[road[1]]=group[road[0]]

print(group[-1])
Problem p02658 (python)

Fixed submission:
n,*l=map(int,open(0).read().split())
a=1
for i in sorted(l):
  a*=i
  if a>10**18: a=-1; break
print(a)

Buggy submission (verdict: Runtime Error):
n=input()
s=list(map(int,(input().split(" "))))
ans=1
for i in s:
    ans*=i
    if ans > 1e18:
        print(-1)
        sys.exit(0)
print(ans)
Problem p03759 (python)

Fixed submission:
a,b,c = [int(i) for i in input().split()]
print("YES" if b-a==c-b else "NO")

Buggy submission (verdict: Runtime Error):
a,b,c = [int(i) for i in input().split()]
print("YES" if b-a==c-b "NO")
Problem p03860 (python)

Fixed submission:
s=input().split()
print(s[0][0]+s[1][0]+s[2][0])

Buggy submission (verdict: Runtime Error):
s = raw_input().split()
print [s[0][0], s[1]][0], s[2][0]].join()
Problem p03951 (python)

Fixed submission:
i=input;N=int(i());s=i();l=i();n=N;j=0
exec("j=max(n*(s[-n:]==l[:n]),j);n-=1;"*N);print(2*N-j)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = input()
l = input()
for i in range(1,N):
    if s[-i:]!=l[:i]:
        a=2*N-i+1
        break
print(a if s!=l else N)
Problem p04040 (python)

Fixed submission:
import scipy.misc as scm

H, W, A, B = [int(i) for i in input().split()]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
import scipy.misc as scm

H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
#H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)
Problem p02713 (python)

Fixed submission:
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            ans += math.gcd(a,l)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(a,l)

print(ans)
Problem p02576 (python)

Fixed submission:
import math
N,X,T = map(int, input().split())
print(math.ceil(N/X)*T)

Buggy submission (verdict: Runtime Error):
import heapq
l=lambda:[int(x) for x in input().split()]
H,W=l()
CH,CW=l()
DH,DW=l()
dh=DH-1
dw=DW-1
S=[[x=='#' for x in list(input())] for _ in range(H)]
q=[(0,0,CH-1,CW-1)]
heapq.heapify(q)
checked=set()
def check(h,w,c):
    if h<0 or h>=H or w<0 or w>=W:
        return
    if S[h][w]:
        return
    p=(abs(dh-h),abs(dw-w))
    heapq.heappush(q,(c,p,h,w))

def main():
    while q:
        c,_,h,w=heapq.heappop(q)
        if h==dh and w==dw:
            return c
        key=(h,w)
        if key in checked:
            continue
        checked.add(key)
        # walk
        check(h-1,w-0,c)
        check(h-0,w-1,c)
        check(h+1,w+0,c)
        check(h+0,w+1,c)
        # warp
        check(h-1,w-1,c+1)
        check(h-1,w+1,c+1)
        check(h+1,w-1,c+1)
        check(h+1,w+1,c+1)
        for i in [-2,+2]:
            for j in range(-2,3):
                check(h+i,w+j,c+1)
                check(h+j,w+i,c+1)
    return -1
print(main())
Problem p02612 (python)

Fixed submission:
N = int(open(0).read())
m = N % 1000
if m == 0:
    print(0)
else:
    print(1000 - m)

Buggy submission (verdict: Runtime Error):
N = int(open(0).read())
m = N % 1000
if m == 0:
    print(0)
else:
    print(1000 - m)
|
Problem p02642 (python)

Fixed submission:
n, *a = map(int, open(0).read().split())           
a.sort()                                           
s = set()                                          
checked = set()                                    
dup = set()                                        
count = 0                                          
for x in a:                                        
    if x in s:                                     
        if x in checked:                           
            dup.add(x)                             
        continue                                   
    count += 1                                     
    checked.add(x)                                 
    for i in range(1, 10**6 // x + 1):             
        s.add(x * i)                               
                                                   
print(count - len(dup))

Buggy submission (verdict: Runtime Error):
import sympy


def calc():
    n, *a = map(int, open(0).read().split())
    black = set()
    r = set()
    for x in a:
        if x in r:
            black.add(x)
        r.add(x)

    r = set(a)
    count = 0
    for x in r:
        if r & black:
            continue
        if r & set(sympy.divisors(x)[:-1]):
            continue
        count += 1
    return count

print(calc())
Problem p02658 (python)

Fixed submission:
import sys
def calc():                                             
    _ = int(sys.stdin.readline())                       
    xs = [int(x) for x in sys.stdin.readline().split(" ")]
    for x in xs:                                          
        if x == 0:                                        
            return 0                                      
    r = 1                                                 
    m = 10 ** 18                                          
    for x in xs:                                          
        r *= x                                            
        if r > m:                                         
            return -1                                     
    return r                                              
                                                          
print(calc())

Buggy submission (verdict: Runtime Error):
import sys
import math                                               
a,b = [float(x) for x in sys.stdin.readline().split(" ")]
c = str(a * b).split(".")[0]                              
print(c)
Problem p02678 (python)

Fixed submission:
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [[] for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

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

n,m,*ab = map(int, open(0).read().split())
to = [[] for _ in range(m+1)]

for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

ans = [None for _ in range(n+1)]
q = deque([1])
while q:
    p = q.pop()
    for i in to[p]:
        if ans[i] is None:
            ans[i] = p
            q.appendleft(i)

print("Yes")
print("\n".join(map(str, ans[2:])))

Buggy submission (verdict: Runtime Error):
n,m,*ab = map(int, open(0).read().split())
to = [[] for _ in range(m+1)]

for i in range(0, m*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].append(b)
    to[b].append(a)

checked = set()
ans = [None for _ in range(n+1)]
def fill(k):
    if k in checked:
        return
    checked.add(k)
    for i in to[k]:
        if ans[i] is None:
            ans[i] = k
    for i in to[k]:
        fill(i)
fill(1)

print("Yes")
print("\n".join(map(str, ans[2:])))

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m,*ab = map(int, open(0).read().split())

to = [set() for _ in range(n+1)]
ans = [None] * (n+1)
for i in range(0, n*2, 2):
    a = ab[i]
    b = ab[i+1]
    to[a].add(b)
    to[b].add(a)

q = deque([1])
while q:
    p = q.pop()
    children = to[p]
    for child in children:
        if ans[child] is None:
            ans[child] = p
            q.appendleft(child)

print("Yes")
print("\n".join(map(str, ans[2:])))

Buggy submission (verdict: Runtime Error):
import math
n,m,*ab = map(int, open(0).read().split())

def calc():
    h = {}
    for i in range(0, n*2, 2):
        a = ab[i]
        b = ab[i+1]
        if a not in h:
            h[a] = set([b])
        else:
            h[a].add(b)
        if b not in h:
            h[b] = set([a])
        else:
            h[b].add(a)

    m = {}
    checked = set()
    def fill(k, d):
        if k in checked:
            return
        checked.add(k)
        if k in m:
            m[k] = min(m[k], d - 1)
        else:
            m[k] = d - 1
        for i in h[k]:
            if i in m:
                m[i] = min(m[i], d)
            else:
                m[i] = d
        for i in h[k]:
            fill(i, d+1)

    fill(1, 1)

    return [m[i] for i in range(2, n+1)]

ans = calc()
if ans is None:
    print("No")
else:
    print("Yes")
    print("\n".join(map(str, ans)))
Problem p02681 (python)

Fixed submission:
import sys                       
a = sys.stdin.readline().rstrip()
b = sys.stdin.readline().rstrip()
if a == b[:-1]:                  
  print("Yes")                   
else:                            
  print("No")

Buggy submission (verdict: Runtime Error):
import sys                       
a = sys.stdin.readline().rstrip()
b = sys.stdin.readline().rstrip()
if a == b[:-1]:                  
  print "Yes"                    
else:                            
  print "No"

Buggy submission (verdict: Runtime Error):
import sys
a = sys.stdin.readline()
b = sys.stdin.readline()
if a == b[:-1]:
  print "Yes"
else:
  print "No"
Problem p02995 (python)

Fixed submission:
import sys
import math

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm(a, b):
  return (a * b) // gcd(a, b)

  
a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
if c == d:
  fgh = (b // c) - ((a - 1) // c)
  n = e - fgh
  print(n) 
else:
  f = (b // c) - ((a - 1) // c)
  g = (b // d) - ((a - 1) // d)
  cd = lcm(c, d) 
  h = (b // cd) - ((a - 1) // cd)
  n = e - f - g + h
  print(n)

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

def lcm(a, b):
  return (a * b) // math.gcd(a, b)


a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)

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

def lcm(a, b):
  return (a * b) // math.gcd(a, b)


a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)

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

a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = math.lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)
Problem p03069 (python)

Fixed submission:
N,S = open(0).read().split()
N=int(N)
S=[s == "." for s in list(S)]

w = sum([1 if s else 0 for s in S])
b = 0
m = w + b
for s in S:
    if s:
        w -= 1
    else:
        b += 1
    m = min(m, w + b)
print(m)

Buggy submission (verdict: Runtime Error):
N,S = open(0).read().split()
N=int(N)
S=list(S)

def calc():
    group = [] if S[0] == '.' else [0]
    n = 0
    mark = S[0]
    for s in S:
        if s == mark:
            n += 1
        else:
            mark = s
            group.append(n)
            n = 1
    if n > 0:
        group.append(n)
    if S[-1] == '#':
        group.pop()

    cnt = 0
    i = 1
    j = len(group) - 1
    while i <= j:
        l = group[i]
        r = group[j]
        if l < r:
            cnt += l
            i += 2
        else:
            cnt += r
            j -= 2
    return cnt

all_w = sum([1 if s == '#' else 0 for s in S])
all_b = sum([1 if s == '.' else 0 for s in S])
lwrb = calc()
print(min(all_w, all_b, lwrb)
Problem p03160 (python)

Fixed submission:
def delta(a, b):                                 
    return abs(a - b)                            
                                                 
n, *hs = [int(x) for x in open(0).read().split()]
l = len(hs)                                      
delta = lambda a, b: abs(hs[a] - hs[b])          
dp = [0, delta(1, 0)]                            
for i in range(2, l):                            
    dp.append(min(                               
        dp[i - 1] + delta(i, i - 1),             
        dp[i - 2] + delta(i, i - 2)))            
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n, k, *hs = [int(x) for x in open(0).read().split()]
dp = [0] * n
for i in range(1, n):
    v = 10000
    for j in range(max(0, i - k), i):
        v = min(v, dp[j] + abs(hs[i] - hs[j]))
    dp[i] = v
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n, k, *hs = [int(x) for x in open(0).read().split()]
dp = [0] * n                                        
for i in range(1, n):                               
    v = 10000                                       
    for j in range(max(0, i - k), i):               
        v = min(v, dp[j] + abs(hs[i] - hs[j]))      
    dp[i] = v                                       
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
n, k, *hs = [int(x) for x in open(0).read().split()]
dp = [0] * n                                        
for i in range(1, n):                               
    v = 10000                                       
    for j in range(max(0, i - k), i):               
        v = min(v, dp[j] + abs(hs[i] - hs[j]))      
    dp[i] = v                                       
print(dp[n-1])