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

Fixed submission:
k, s = list(map(int, input().split()))

p = s
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

if len(factors) == 0:
    print(1)
else:
    primes = list(factors.keys())
    exp = [0] * len(primes)
    upper = s/k
    ans = 1

    while exp[0] <= factors[primes[0]]:
        num = 1
        for i in range(len(primes)):
            num *= pow(primes[i], exp[i])

        if num == upper:
            ans = num
            break
        elif num < upper:
            ans = max(ans, num)

        index = len(primes)-1
        done = False
        while not done:
            exp[index] += 1
            if exp[index] > factors[primes[index]]:
                if index == 0:
                    break
                else:
                    exp[index] = 0
                    index -= 1
            else:
                done = True

    print(ans)

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

p = s
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

primes = list(factors.keys())
exp = [0] * len(primes)
upper = s/k
ans = 1

while exp[0] <= factors[primes[0]]:
    num = 1
    for i in range(len(primes)):
        num *= pow(primes[i], exp[i])

    if num == upper:
        ans = num
        break
    elif num < upper:
        ans = max(ans, num)

    index = len(primes)-1
    done = False
    while not done:
        exp[index] += 1
        if exp[index] > factors[primes[index]]:
            if index == 0:
                break
            else:
                exp[index] = 0
                index -= 1
        else:
            done = True

print(ans)
Problem p03244 (python)

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

first = {}
second = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in first:
            first[v[i]] += 1
        else:
            first[v[i]] = 1
    else:
        if v[i] in second:
            second[v[i]] += 1
        else:
            second[v[i]] = 1

first = sorted(first.items(), key=lambda x: x[1])
second = sorted(second.items(), key=lambda x: x[1])

f = first.pop()
s = second.pop()

if f[0] == s[0]:
    if len(first) >= 1:
        if len(second) >= 1:
            f2 = first.pop()
            s2 = second.pop()

            if f2[1] + s[1] > f[1] + s2[1]:
                f = f2
            else:
                s = s2
        else:
            s = second.pop()
    elif len(second) >= 1:
        f = first.pop()
    else:
        s = (0, 0)

print(n-f[1]-s[1])

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


first = {}
second = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in first:
            first[v[i]] += 1
        else:
            first[v[i]] = 1
    else:
        if v[i] in second:
            second[v[i]] += 1
        else:
            second[v[i]] = 1

first = sorted(first.items(), key=lambda x: x[1])
second = sorted(second.items(), key=lambda x: x[1])

f = first.pop()
s = second.pop()

if f[0] == s[0]:
    if len(first) >= 1:
        if len(second) >= 1:
            f2 = first.pop()
            s2 = second.pop()

            if f2[1] > s2[2]:
                f = f2
            else:
                s = s2
        else:
            s = second.pop()
    elif len(second) >= 1:
        f = first.pop()
    else:
        s = (0, 0)

print(n-f[1]-s[1])
Problem p03274 (python)

Fixed submission:
from bisect import bisect_left

n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

pos = bisect_left(x, 0)
if pos < len(x) and x[pos] == 0:
    k -= 1
else:
    x.insert(pos, 0)

l = pos
r = pos+k

if r >= len(x):
    diff = r-len(x) + 1
    l -= diff
    r -= diff

ans = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])

while r >= pos:
    if l < 0:
        break

    dist = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])
    if dist < ans:
        ans = dist

    l -= 1
    r -= 1

print(ans)

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

n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

pos = bisect_left(x, 0)
if x[pos] == 0:
    k -= 1
else:
    x.insert(pos, 0)

l = pos
r = pos+k

if r >= len(x):
    diff = r-len(x) + 1
    l -= diff
    r -= diff

ans = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])

while r >= pos:
    if l < 0:
        break

    dist = min(abs(x[l]), x[r])*2 + max(abs(x[l]), x[r])
    if dist < ans:
        ans = dist

    l -= 1
    r -= 1

print(ans)
Problem p03319 (python)

Fixed submission:
import math
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

print(math.ceil((n-1)/(k-1)))

Buggy submission (verdict: Runtime Error):
index = a.index(1)
cnt = 0

if (n==k):
    print(1)
else:
    if index <= (k - 1):
        cnt += 1
        i = k - 1
        while i <= (len(a) - 2):
            i += (k-1)
            cnt += 1
    elif index >= (n - k):
        cnt += 1
        i = n - k
        while i >= 1:
            i -= (k-1)
            cnt += 1
    else:
        i = index
        while i >= 1:
            i -= (k-1)
            cnt += 1

        i = index
        while i <= (len(a) - 2):
            i += (k-1)
            cnt += 1

    print(cnt)
Problem p03456 (python)

Fixed submission:
N = int(input().replace(" ", ""))
 
print("Yes" if round(N**0.5)**2 == N else "No")

Buggy submission (verdict: Runtime Error):
N = int(input().remove(" ", ""))

print("Yes" if round(N**0.5)**2 == N else "No")
Problem p03569 (python)

Fixed submission:
s = input()

l = 0
r = len(s)-1
cnt = 0

while l < r:
    lx = 0
    while s[l] == "x" and l < len(s)-1:
        lx += 1
        l += 1

    rx = 0
    while s[r] == "x" and r > 0:
        rx += 1
        r -= 1

    if s[l] == s[r]:
        cnt += abs(rx-lx)

        l += 1
        r -= 1
    else:
        cnt = -1
        break

print(cnt)

Buggy submission (verdict: Runtime Error):
s = input()

l = 0
r = len(s)-1
cnt = 0

while l < r:
    lx = 0
    while s[l] == "x":
        lx += 1
        l += 1

    rx = 0
    while s[r] == "x":
        rx += 1
        r -= 1

    if s[l] == s[r]:
        cnt += abs(rx-lx)

        l += 1
        r -= 1
    else:
        cnt = -1
        break

print(cnt)
Problem p03607 (python)

Fixed submission:
n = int(input())
a = {}

cnt = 0
for i in range(n):
    ai = int(input()) - 1

    if ai in a:
        cnt -= 1
        del a[ai]
    else:
        cnt += 1
        a[ai] = 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [False] * int(1e9)

cnt = 0
for i in range(n):
    ai = int(input()) - 1
    a[ai] = not a[ai]

    if a[ai]:
        cnt += 1
    else:
        cnt -= 1

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [False] * 100000

cnt = 0
for i in range(n):
    ai = int(input()) - 1
    a[ai] = not a[ai]

    if a[ai]:
        cnt += 1
    else:
        cnt -= 1

print(cnt)
Problem p03951 (python)

Fixed submission:
n = int(input())
s = input()
t = input()

if (n == len(s) and (s == t)):
    print(n)
else:
    ind = [0]
    for i in range(1, len(s)):
        if s[-i:] == t[:i]:
            ind.append(i)

    ind.reverse()
    for i in ind:
        if i == 0:
            print(2*n)
        else:
            res = s[0:-i] + t
            if len(res) >= n:
                print(len(res))
                break

Buggy submission (verdict: Runtime Error):
if (n == len(s) and (s == t)):
    print(n)
else:
    ind = [0]
    for i in range(1, len(s)):
        if s[-i:] == t[:i]:
            ind.append(i)

    ind.reverse()
    for i in ind:
        if i == 0:
            print(2*n)
        else:
            res = s[0:-i] + t
            if len(res) >= n:
                print(len(res))
                break
Problem p04045 (python)

Fixed submission:
n, k = input().split()
d = list(map(int, input().split()))

a = []

for i in range(10):
    if i not in d:
        a.append(i)

n = list(map(int, list(n)))

for i in range(len(n)):
    if n[i] in d:
        ind = i

        done = False
        while not done:
            for j in range(n[ind]+1, 10):
                if j in a:
                    n[ind] = j
                    done = True
                    break

            if not done:
                ind -= 1

                if ind < 0:
                    n.insert(0, a[1] if a[0] == 0 else a[0])
                    ind = 0
                    done = True

        for j in range(ind+1, len(n)):
            n[j] = a[0]

        break

print("".join(list(map(str, n))))

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

a = []

for i in range(10):
    if i not in d:
        a.append(i)

n = list(map(int, list(n)))

for i in range(len(n)):
    if n[i] in d:
        ind = i

        done = False
        while not done:
            for j in range(n[ind]+1, 10):
                if j in a:
                    n[ind] = j
                    done = True
                    break

            if not done:
                ind -= 1

                if ind < 0:
                    n.insert(0, a[1] if a[0] == 0 else a[0])
                    ind = 0
                    done = True

        for j in range(ind+1, len(n)):
            n[j] = a[0]

        break

print("".join(list(map(str, n))))
Problem p02630 (python)

Fixed submission:
from collections import Counter

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

Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

d = Counter(A)

sub_s = sum(A)

for b, c in BC:
    sub_s += d[b] * (c - b)
    d[c] += d[b]
    d[b] = 0

    print(sub_s)

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

import sys

readline = sys.stdin.buffer.readline

def solver(int N, list A, int Q, list BC):
    d = Counter(A)

    sub_s = sum(A)

    for b, c in BC:
        sub_s += d[b] * (c - b)
        d[c] += d[b]
        d[b] = 0

        print(sub_s)


def run():
    N = int(readline())
    A = list(map(int, readline().split()))

    Q = int(readline())
    BC = [list(map(int, readline().split())) for _ in range(Q)]

    solver(N, A, Q, BC)

run()
Problem p02641 (python)

Fixed submission:
import numpy as np

X, N = map(int, input().split())
P = np.array(list(map(int, input().split())))

P = P - X

for i in range(0, X + 1):
    if i not in P or -i not in P:
        if -i not in P:
            ans = X - i
        else:
            ans = X + i
        break

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

X, N = map(int, input().split())
P = np.array(list(map(int, input().split())))

P = P - X

for i in range(0, X):
    if i not in P or -i not in P:
        if -i not in P:
            ans = X - i
        else:
            ans = X + i
        break

print(ans)
Problem p02664 (python)

Fixed submission:
T = list(input())

if len(T) == 1:
    if T[0] == '?':
        T[0] = 'D'
else:

    if T[0] == '?':
        if T[1] == 'D':
            T[0] = 'P'
        else:
            T[0] = 'D'

    for i in range(1, len(T) - 1):
        if T[i] == '?':
            if T[i - 1] == 'P':
                T[i] = 'D'
            else:
                if T[i + 1] == 'D':
                    T[i] = 'P'
                else:
                    T[i] = 'D'

    if T[-1] == '?':
        T[-1] = 'D'

print(''.join(T))

Buggy submission (verdict: Runtime Error):
T = list(input())

if T[0] == '?':
    if T[1] == 'D':
        T[0] = 'P'
    else:
        T[0] = 'D'

for i in range(1, len(T) - 1):
    if T[i] == '?':
        if T[i - 1] == 'P':
            T[i] = 'D'
        else:
            if T[i + 1] == 'D':
                T[i] = 'P'
            else:
                T[i] = 'D'

if T[-1] == '?':
    T[-1] = 'D'

print(''.join(T))
Problem p02684 (python)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline


def solver(N, K, A):
    i = 0
    i_list = [0]
    reached = [False for _ in range(N)]

    while True:
        next_i = A[i]

        if reached[next_i]:
            break

        reached[next_i] = True

        i_list.append(next_i)
        i = next_i

    m = i_list.index(next_i)

    if m >= K:
        return i_list[K] + 1

    le = len(i_list) - m
    K -= m
    ind = K % le

    return i_list[m + ind] + 1


def run():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A = [a - 1 for a in A]

    ans = solver(N, K, A)
    print(ans)


run()

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

B = [A[0]]

for _ in range(1, N + 10):
    b = A[B[-1] - 1]
    if b in B:
        B += [b]
        break
    else:
        B += [b]
        continue

if len(B) >= K:
    print(B[K])
else:
    ind = [i for i, x in enumerate(B) if x == b]

    K = K - ind[0]
    mod = K % (ind[1] - ind[0])

    print(B[ind[0] + mod - 1])
Problem p02731 (python)

Fixed submission:
L = int(input())

ans = L**3 / 27

print(ans)

Buggy submission (verdict: Runtime Error):
import collections
import copy

N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)

for a in A:
    pC = copy.deepcopy(C)

    ans = 0
    for k, v in pC.items():
        if k == a:
            ans += (v - 1) * (v - 2) // 2
        else:
            ans += v * (v - 1) // 2
    print(ans)
Problem p02855 (python)

Fixed submission:
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    H, W, K = map(int, readline().split())
    S = read().split()
    S = list(map(lambda x: x.decode('UTF-8'), S))

    A = np.zeros([H, W], dtype=np.int32)
    h_num = 0
    ih = []
    for h in range(H):
        ii = 0
        for w in range(W):
            if S[h][w] == "#":
                if ii != 0:
                    h_num += 1
                    A[h:, w:] = h_num
                else:
                    h_num += 1
                    A[h:, :] = h_num
                    ii += 1
                    ih.append(h)

    h_num = 0
    if A[0, 0] == 0:
        for h in range(ih[0]+1):
            ii = 0
            for w in range(W):
                if S[h][w] == "#":
                    if ii != 0:
                        h_num += 1
                        A[0:h, w:] = h_num
                    else:
                        h_num += 1
                        A[0:h, :] = h_num
                        ii += 1

    for h in range(H):
        print(' '.join(map(str, A[h])))


main()

Buggy submission (verdict: Runtime Error):
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    H, W, K = map(int, readline().split())
    S = read().split()
    S = list(map(lambda x: x.decode('UTF-8'), S))

    A = np.zeros([H, W], dtype=np.int32)
    h_num = 0
    ih = []
    for h in range(H):
        ii = 0
        for w in range(W):
            if S[h][w] == "#":
                if ii != 0:
                    h_num += 1
                    A[h:, w:] = h_num
                    ih.append(h)
                else:
                    h_num += 1
                    A[h:, :] = h_num
                    ii += 1

    h_num = 0
    if A[0, 0] == 0:
        for h in range(ih[0]+1):
            ii = 0
            for w in range(W):
                if S[h][w] == "#":
                    if ii != 0:
                        h_num += 1
                        A[0:h, w:] = h_num
                    else:
                        h_num += 1
                        A[0:h, :] = h_num
                        ii += 1

    for h in range(H):
        print(' '.join(map(str, A[h])))


main()
Problem p02947 (python)

Fixed submission:
import collections

N = int(input())

s = []
ps = []
for i in range(N):
    ps = sorted(list(input()))
    s.append(''.join(ps))

d = collections.Counter(s)

cnt = 0
for v in d.values():
    if v != 1:
        cnt += int(v * (v-1) / 2)

print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys

from scipy.special import comb

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = read().split()
    S = list(map(lambda x: sorted(x.decode('UTF-8')), S))

    A = defaultdict(int)
    for i in range(N):
        s = ''.join(S[i])
        A[s] += 1

    cnt = 0
    for i in A.values():
        cnt += comb(i, 2)
    print(int(cnt))


main()
Problem p02983 (python)

Fixed submission:
import sys

L, R = list(map(int, input().split()))

yy = 2019

d = 2019

if R > L+2019:
    R = L+2019

for i in range(L,R):
    im = i % yy

    for j in range(i+1, R+1):
        jm = j % yy

        if im * jm % yy <= d:
            d = im * jm % yy

print(d)

Buggy submission (verdict: Runtime Error):
import numpy as np

L, R = map(int, input().split())

if L - R >= 2019:
    ans = 0
else:
    A = np.arange(L, R + 1)
    A = np.sort(A % 2019)
    ans = A[0] * A[1]

print(ans % 2019)
Problem p03005 (python)

Fixed submission:
import sys

N, K  = list(map(int, input().split()))

if K == 1:
    print(0)
    sys.exit()

print(N-K)

Buggy submission (verdict: Runtime Error):
package main

import "fmt"


func main() {
	var N, K int
	fmt.Scan(&N, &K)
	a := N % K
	if a == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}
Problem p03006 (python)

Fixed submission:
import itertools
from collections import defaultdict


def main():
    N = int(input())
    if N == 1:
        print(1)

    else:
        XY = [list(map(int, input().split())) for _ in range(N)]

        dd = defaultdict(int)

        for xy1, xy2 in itertools.combinations(XY, 2):
            a = (xy2[0] - xy1[0], xy2[1] - xy1[1])
            b = (-a[0], -a[1])
            dd[a] += 1
            dd[b] += 1

        print(N - max(dd.values()))


main()

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


def main():
    N = int(input())
    XY = [list(map(int, input().split())) for _ in range(N)]

    dd = defaultdict(int)
    for i in range(N - 1):
        for j in range(i + 1, N):
            a = (XY[j][0] - XY[i][0], XY[j][1] - XY[i][1])
            dd[a] += 1

    pq = max(dd, key=dd.get)

    cnt = 0
    for x, y in XY:
        if [x + pq[0], y + pq[1]] in XY:
            cnt += 1

    print(N - cnt)


main()
Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

left = 1
right = N

for l, r in LR:
    left = max(left, l)
    right = min(right, r)

ans = right - left

print(ans + 1 if ans >= 0 else 0)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

cnt = 0

NM = np.zeros([M,N])

for i in range(M):
    A = input().split()
    NM[i,int(A[0])-1:int(A[1])] = 1.0

s = np.sum(NM,axis=0)

print(np.sum(s==M))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

cnt = 0

NM = np.zeros([M,N])

for i in range(M):
    A = input().split()
    NM[i,int(A[0])-1:int(A[1])] = 1.0

print(NM)

s = np.sum(NM,axis=0)
print(s)

print(np.sum(s==M))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

cnt = 0

NM = np.zeros([M,N])

for i in range(M):
    A = input().split()
    NM[i,int(A[0]):int(A[1])] = 1.0

s = np.sum(NM,axis=0)

print(np.sum(s==M))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

A = np.zeros([2,M])

cnt = 0

for i in range(M):
    A[:,i] = input().split()

A = np.array(A,dtype=np.int64)


NM = np.zeros([M,N])

for i in range(M):
    NM[i,A[0,i]-1:A[1,i]] = 1.0


s = np.sum(NM,axis=0)

print(np.sum(s==M))
Problem p03062 (python)

Fixed submission:
import sys

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


ans = 0
for a in A:
    ans += abs(a)

c = 0
m = abs(A[0])
for a in A:
    if a < 0:
        c += 1
    elif a == 0:
        print(ans)
        sys.exit()

    if abs(a) < m:
        m = abs(a)

if c % 2 == 0:
    print(ans)
else:
    print(ans - 2 * m)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

N = int(input())

A = input().split()
A = np.array([int(x) for x in A])

if np.sum(A==0) != 0:
# Aに0が含まれる場合
    # 最後に0が出てくる場所
    z = np.max(np.where(A==0))
    B = A[z:N]

    # B = [0 -?]のときだけ例外
    if B.shape[0] == 2 and B[-1] < 0:
        sign = 1
        break

    elif np.sum(B < 0)%2 ==0:
        sign = 1
    else:
        sign = -1

# Aに0が含まれない場合
else:
    if np.sum(A < 0)%2 ==0:
        sign = 1
    else:
        sign = -1

print(np.abs(A[0:N-1]).sum() + sign*abs(A[-1]))
Problem p03068 (python)

Fixed submission:
import sys

N = int(input())
S = input()
K = int(input())

SS = []

for i in range(N):
  if S[i] == S[K-1]:
    SS.append(S[i])
  else:
    SS.append("*")
    
print(''.join(SS))

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
S = input()
K = int(input())

SS = []

for i in range(N):
  if S[i] == S[K]:
    SS.append(S[i])
  else:
    SS.append("*")
    
print(''.join(SS))
Problem p03086 (python)

Fixed submission:
S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0
ans.append(ll)

print(max(ans))

Buggy submission (verdict: Runtime Error):
S = input()
AA = ["A", "C", "G", "T"]

ans = []
ll = 0
for i in range(len(S)):
    if S[i] in AA:
        ll += 1
    else:
        ans.append(ll)
        ll = 0

print(max(ans))
Problem p03162 (python)

Fixed submission:
def main():
    N = int(input())

    dp = [0] * 3
    n_dp = [0] * 3

    for _ in range(N):
        a = list(map(int, input().split()))
        for j in range(3):
            n_dp[j] = max(dp[j-2] + a[j], dp[j-1] + a[j])
        dp = n_dp.copy()

    print(max(dp))


main()

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(input())

    dp = [0] * 3
    n_dp = [0] * 3
    for _ in range(N):
        a = list(map(int, readline().split()))
        for j in range(3):
            n_dp[j] = max(dp[j-2] + a[j], dp[j-1] + a[j])
        dp = n_dp.copy()

    print(max(dp))


main()
Problem p03163 (python)

Fixed submission:
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, W = map(int, readline().split())
    WV = np.array([[int(x) for x in readline().split()] for _ in range(N)])

    dp = np.zeros([W+1], np.int64)

    for w, v in WV:
        np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

    print(np.max(dp))


main()

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.buffer.readline


def main():
    N, K = map(int, readline().split())
    H = list(map(int, readline().split()))
    for i in range(K):
        H.append(10**10)

    dp = [10**10] * (N+K)
    dp[0] = 0

    for i in range(N):
        for k in range(1, K+1):
            dp[i+k] = min(dp[i+k], dp[i] + abs(H[i+k]-H[i]))

    print(dp[N-1])


main()