Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n1, n2 = [int(i) for i in input().split()]

r1 = 2018
for i3 in range(n2 - n1):
    n4 = i3 + n1

    t1 = n2 -n4
    if t1 >= 2019:
        t1 = 2019
    for i5 in range(t1):
        n5 = i5 + n4 + 1

        if ((n4 * n5) % 2019)  < r1:
            r1 = ((n4 * n5) % 2019)

print(r1)

Fixed submission:
import sys

n1, n2 = [int(i) for i in input().split()]

r1 = 2018

if n2 - n1 >= 2019:
    print(0)
    sys.exit()


for i3 in range(n2 - n1):
    n4 = i3 + n1

    t1 = n2 - n4
    if t1 >= 2019:
        t1 = 2019
    for i5 in range(t1):
        n5 = i5 + n4 + 1

        if ((n4 * n5) % 2019)  < r1:
            r1 = ((n4 * n5) % 2019)

print(r1)

Buggy python submission (verdict: Time Limit Exceeded):
n1, n2 = [int(i) for i in input().split()]

r1 = 2018
for i3 in range(n2 - n1):
    n4 = i3 + n1

    for i5 in range(n2 - n4):
        n5 = i5 + n4 + 1

        if ((n4 * n5) % 2019)  < r1:
            r1 = ((n4 * n5) % 2019)

print(r1)

Fixed submission:
import sys

n1, n2 = [int(i) for i in input().split()]

r1 = 2018

if n2 - n1 >= 2019:
    print(0)
    sys.exit()


for i3 in range(n2 - n1):
    n4 = i3 + n1

    t1 = n2 - n4
    if t1 >= 2019:
        t1 = 2019
    for i5 in range(t1):
        n5 = i5 + n4 + 1

        if ((n4 * n5) % 2019)  < r1:
            r1 = ((n4 * n5) % 2019)

print(r1)
Buggy python submission (verdict: Runtime Error):
n1, n2  = [int(i) for i in input().split()]

na3 = []

for i4 in range(n1):
    na3.append([int(j) for j in input().split()])

na5 = [0] * n2

for i6 in range(n1):
    for i7 in range(na3[i6][0] + 1):
        if i7 != 0:
            na5[na3[i6][i7 - 1]] += 1
            
r8 = 0
for i9 in range(n2):
    if na5[i9] == n1:
        r8 += 1

print(r8)

Fixed submission:
n1, n2  = [int(i) for i in input().split()]

na3 = []

for i4 in range(n1):
    na3.append([int(j) for j in input().split()])

na5 = [0] * (n2 + 1)

for i6 in range(n1):
    for i7 in range(na3[i6][0] + 1):
        if i7 != 0:
            na5[na3[i6][i7]] += 1

r8 = 0
for i9 in range(n2 + 1):
    if na5[i9] == n1:
        r8 += 1

print(r8)
Buggy python submission (verdict: Runtime Error):

n1 = int(input())

n2 = [int(i) for i in input().split()]

n3 = []
n4 = []
for i1 in range(n1):
    if i1 % 2 == 0:
        n3.append(n2[i1])
    else:
        n4.append(n2[i1])

n3.sort()
n4.sort()

t1 = 0
c1 = 0
n5 = []

for i2 in range(len(n3)):
    if n3[i2] == t1:
        c1 += 1
        if i2 == len(n3) - 1:
            n5.append([t1, c1])
    else:
        if i2 != 0:
            n5.append([t1, c1])
        t1 = n3[i2]
        c1 = 1
        if i2 == len(n3) - 1:
            n5.append([t1, c1])

t1 = 0
c1 = 0
n6 = []
for i3 in range(len(n4)):
    if n4[i3] == t1:
        c1 += 1
        if  i3 == len(n4) - 1:
            n6.append([t1, c1])
    else:
        if i3 != 0:
            n6.append([t1, c1])
        t1 = n4[i3]
        c1 = 1
        if  i3 == len(n4) - 1:
            n6.append([t1, c1])

n5.sort(key=lambda x:x[1], reverse=True)
n6.sort(key=lambda x:x[1], reverse=True)

t2 = 0
t2 = 0

r1 = 0

for i4 in range(n1 // 2):
    if i4 == (n1 // 2) - 1:
        r1 = n1 // 2
        break
    if n5[i4][0] == n6[i4][0]:
        if n5[i4][1] > n6[i4][1]:
            r1 = n1 - n5[i4][1] - n6[i4 + 1][1]
            break
        elif n5[i4][1] < n6[i4][1]:
            r1 = n1 - n5[i4 + 1][1] - n6[i4][1]
            break
    else:
        r1 = n1 - n5[i4][1] - n6[i4][1]
        break

print(r1)


Fixed submission:
n1 = int(input())

n2 = [int(i) for i in input().split()]

n3 = []
n4 = []
for i1 in range(n1):
    if i1 % 2 == 0:
        n3.append(n2[i1])
    else:
        n4.append(n2[i1])

n3.sort()
n4.sort()

t1 = 0
c1 = 0
n5 = []

for i2 in range(len(n3)):
    if n3[i2] == t1:
        c1 += 1
        if i2 == len(n3) - 1:
            n5.append([t1, c1])
    else:
        if i2 != 0:
            n5.append([t1, c1])
        t1 = n3[i2]
        c1 = 1
        if i2 == len(n3) - 1:
            n5.append([t1, c1])

t1 = 0
c1 = 0
n6 = []
for i3 in range(len(n4)):
    if n4[i3] == t1:
        c1 += 1
        if  i3 == len(n4) - 1:
            n6.append([t1, c1])
    else:
        if i3 != 0:
            n6.append([t1, c1])
        t1 = n4[i3]
        c1 = 1
        if  i3 == len(n4) - 1:
            n6.append([t1, c1])

n5.sort(key=lambda x:(x[1],x[0]), reverse=True)
n6.sort(key=lambda x:(x[1],x[0]), reverse=True)

r1 = 0

if len(n5) == 1 and len(n6) == 1 and n5[0][0] == n6[0][0]:
     r1 = n1 // 2
else:
    if n5[0][0] != n6[0][0]:
        r1 = n1 - n5[0][1] - n6[0][1]
    else:
        if len(n5) == 1:
            r1 = n1 - n5[0][1] - n6[1][1]
        elif len(n6) == 1:
            r1 = n1 - n5[1][1] - n6[0][1]
        else:
            if (n1 - n5[0][1] - n6[1][1]) >= (n1 - n5[1][1] - n6[0][1]):
                r1 = r1 = n1 - n5[1][1] - n6[0][1]
            else:
                r1 = n1 - n5[0][1] - n6[1][1]

print(r1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
P = list(map(int, input().split(' ')))

count = 1
for i in range(1, n):
    if min(P[:i+1]) == P[i]:
        count += 1
print(count)


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

count = 0
minimum = 2 * 10 ** 5 + 1
for p in P:
    if p < minimum:
        count += 1
        minimum = p
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
P = list(map(int, input().split(' ')))

count = 1
for i in range(1, n):
    if min(P[:i+1]) == P[i]:
        count += 1
print(count)

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

count = 0
minimum = 2 * 10 ** 5 + 1
for p in P:
    if p < minimum:
        count += 1
        minimum = p
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
P = list(map(int, input().split(' ')))

count = 0
for i in range(n):
    if i == 0:
        count += 1
    elif min(P[i], min(P[:i])) == P[i]:
        count += 1

print(count)

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

count = 0
minimum = 2 * 10 ** 5 + 1
for p in P:
    if p < minimum:
        count += 1
        minimum = p
print(count)
Buggy python submission (verdict: Runtime Error):
import numpy as np

a, b = map(int, input().split(' '))
lcm = np.lcm(a, b)
print(lcm)

Fixed submission:
from fractions import gcd

a, b = [int(val) for val in input().split(' ')]
lcm = int((a*b)/gcd(a, b))
print(lcm)

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

a, b = map(int, input().split(' '))
lcm = int((a * b) / math.gcd(a, b))
print(lcm)

Fixed submission:
from fractions import gcd

a, b = [int(val) for val in input().split(' ')]
lcm = int((a*b)/gcd(a, b))
print(lcm)
Buggy python submission (verdict: Runtime Error):
s = input()
days = ['SUN','MON','TUE','WED','THU','FRI','SAT']
index = days.index(s)
print(7-index)

Fixed submission:
s = input()
days = ['SUN','MON','TUE','WED','THU','FRI','SAT']
index = days.index(s)
print(7-index)
Buggy python submission (verdict: Runtime Error):
n = int(input())
strings = input()
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

new_strings = ''
for s in strings:
    index = letters.index(s)
    added_index = index + n
    new_index = added_index % 26
    new_s = letters[new_index]
    new_strings += new_s

print(new_strings)

Fixed submission:
n = int(input())
strings = input()
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

new_strings = ''
for s in strings:
    index = letters.index(s)
    added_index = index + n
    new_index = added_index % 26
    new_s = letters[new_index]
    new_strings += new_s

print(new_strings)
Buggy python submission (verdict: Runtime Error):
h, a = map(int, input().split())
print(h // a + boll(h % a))

Fixed submission:
h, a = map(int, input().split())
print(h // a + bool(h % a))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ls = []
for i in range(m):
    l, r = map(int, input().split())
    ln = l
    while r >= ln:
        ls.append(ln)
        ln += 1
ls_duplicate = [x for x in set(ls) if ls.count(x) > (m-1)]
print(len(ls_duplicate))


Fixed submission:
n, m = map(int, input().split())
snum = 0
bnum = 100000
for i in range(m):
    l, r = map(int, input().split())
    if l >= snum:
        snum = l
    if r <= bnum:
        bnum = r
if snum > bnum:
    print(0) 
else:
    print(bnum - snum + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ls = []
cnt = 0
for i in range(m):
    l, r = map(int, input().split())
    ln = l
    while r >= ln:
        ls.append(ln)
        ln += 1
for i in range(ln):
    if ls.count(i) == m:
        cnt += 1
print(cnt) 


Fixed submission:
n, m = map(int, input().split())
snum = 0
bnum = 100000
for i in range(m):
    l, r = map(int, input().split())
    if l >= snum:
        snum = l
    if r <= bnum:
        bnum = r
if snum > bnum:
    print(0) 
else:
    print(bnum - snum + 1)
Buggy python submission (verdict: Runtime Error):
n, k = input().split()
s = input()
num = 3
if (num - int(k)) == 0:
    sn = s[0] + s[1] + s[int(k)-1].lower()
    print(sn)
if (num - int(k)) == 1:
    sn = s[0] + s[int(k)-1].lower() + s[2]
    print(sn)
if (num - int(k)) == 2:
    sn = s[int(k)-1].lower() + s[1] + s[2]
    print(sn)


Fixed submission:
n, k = input().split()
s = input()
sn = s[int(k)-1].lower()
num1 = int(k) - 1
num2 = int(k)
print(s[:num1] + sn + s[num2:])
Buggy python submission (verdict: Runtime Error):
n = list(input())
for num in n:
    if num ==1:
        num=9
    elif num==1:
        num=9:
print(n)

Fixed submission:
n = list(input())
for num in n:
    if num == '1':
        num ='9'
    elif num == '9':
        num = '1'
    print(num,end='')
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, raw_input().split())

print(max([a, b, c])*10+sum([a,b,c])-max([a,b,c]))

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

print(max([a, b, c])*10+sum([a,b,c])-max([a,b,c]))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
s = input()
ans = 0
for i in range(len(s)):
    if s[i] == "-":
        if i == a and len(s)-i-1 == b:
            ans = 1
            for j in range(b):
                if s[-j] == "-":
                    ans = 0
                    break
            break
if ans == 0:
    print("No")
else:
    print("Yes")
            

Fixed submission:
N = int(input())
d = []
for i in range(N):
    d.append(int(input()))
print(len(set(d)))
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = list(input())
s.sort()
t.sort()
t.reverse()
for i in range(len(s)):
    if s[len(s)-1] == t[len(s)-1]:
        if len(s) < len(t):
            print("Yes")
        else:
            print("No")
        break
    if s[i] < t[i]:
        print("Yes")
        break
    elif s[i] == t[i]:
        continue
    else:
        print("No")
        break


Fixed submission:
s = list(input())
t = list(input())
s.sort()
t.sort()
t.reverse()
for i in range(min(len(s),len(t))):
    if s[i] < t[i]:
        print("Yes")
        break
    elif s[i] == t[i]:
        if s[min(len(s),len(t))-1] == t[min(len(s),len(t))-1]:
            if len(s) < len(t):
                print("Yes")
                break
            else:
                print("No")
                break
        continue
    else:
        print("No")
        break
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n, k = (int(i) for i in input().split())
l = list(int(j) for j in input().split())
ans = 0
for i in itertools.combinations(l, k):
    if sum(i) > ans:
        ans = sum(i)
print(ans)


Fixed submission:
n, k = (int(i) for i in input().split())
l = list(int(j) for j in input().split())
ans = 0
for i in range(k):
    ans += max(l)
    l.remove(max(l))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
wb = []
cnt = 0
num_before = 1
light = 1
for i in range(n):
    a.append(int(input()))
while light != 2:
    wb.append(light)
    light = a[num_before-1]
    num_before = light
    if light in wb:
        print(-1)
        break 
    cnt += 1
if light == 2:
    print(cnt)

Fixed submission:
a = [int(input()) for i in range(int(input()))]
i = a[0]
cnt = 1
while(i != 2 and cnt <= 10**5):
    i = a[i-1]
    cnt += 1
if cnt <= 10**5:
    print(cnt)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a > b:
    print("GREATER")
elif a = b:
    print("EQUAL")
else:
    print("LESS")

Fixed submission:
a = int(input())
b = int(input())
if a > b:
    print("GREATER")
if a == b:
    print("EQUAL")
if a < b:
    print("LESS")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
pwr = 1
for i in range(1,n+1):
    pwr = pwr*i
print(pwr%(10**9+7))

Fixed submission:
n = int(input())
pwr = 1
for i in range(1,n+1):
    pwr = pwr*i
    pwr = pwr%(10**9+7)
print(pwr)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
cnt = 0
for i in range(a,b+1):
    if i%x == 0:
        cnt += 1
print(cnt)

Fixed submission:
a, b, x = map(int, input().split())
cnt = 0
if (a%x == 0):
    cnt+=1
cnt += b//x - a//x
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
count = 0
for i in range(a,b+1):
    if i%x == 0:
        count += 1
print(count)

Fixed submission:
a, b, x = map(int, input().split())
cnt = 0
if (a%x == 0):
    cnt+=1
cnt += b//x - a//x
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
ans =[]
for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    elif s[i] == '1':
        ans.append('1')
    elif s[i] == 'B':
        ans.pop(-1)
print(''.join(ans))

Fixed submission:
s = input()
ans =[]
for i in range(len(s)):
    if s[i] == '0':
        ans.append('0')
    elif s[i] == '1':
        ans.append('1')
    elif len(ans) != 0:
        ans.pop(-1)
print(''.join(ans))
Buggy python submission (verdict: Runtime Error):
a = list(map(int, raw_input().split()))

a.sort()

if a == [5,5,7]:
    print("YES")
else:
    print("NO")

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

a.sort()

if a == [5,5,7]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
import sys


def InS(): return input()


def InL(): return list(map(int, input().split()))


def InI(): return int(input())


N, K = InL()
H = InL().sort()

if K >= N:
    print(0)
    sys.exit()

print(sum(H[0:N-K]))


Fixed submission:
import sys


def InS(): return input()


def InL(): return list(map(int, input().split()))


def InI(): return int(input())


N, K = InL()
H = InL()
H.sort()

if K >= N:
    print(0)
    sys.exit()
else:
    print(sum(H[0:N-K]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))
b = b[::-1]
a = []
cont0 = False
a.append(b[0])
if len(b) == 1:
	print(2*b[0])
	quit() 
if b[0] > b[1]:
	a.append(b[1])
	a.append(b[1])
elif b[0] == b[1]:
	a.append(b[0])
	a.append(b[0])
elif b[0] < b[1]:
	a.append(b[0])
	a.append(b[1])
if len(b) == 2:
	print(sum(a))
	quit()
for i in range(2,n-1):
	if not cont0
		if b[i-2] > b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = b[i]
				a.append(b[i])
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
		elif b[i-2] == b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = b[i]
				a.append(b[i])
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
		elif b[i-2] < b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = 0
				a.append(0)
				cont0 = True
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
	else:
		if b[i-1] < b[i]:
			a.append(b[i])
		else:
			a.append(0)
		cont0 = False

print(sum(a))



Fixed submission:
n = int(input())
b = list(map(int, input().split()))
c = []
c.append(b[0])
for i in range(1,n-1):
	c.append(min(b[i-1], b[i]))
c.append(b[-1])
print(sum(c))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

print(sum[1 for i in range(3) if s[i] == t[i]])

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

print(sum([1 for i in range(3) if s[i] == t[i]]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
maxs = []
for i in range(n):
	a2 = a[i]
	a[i] = 0
	maxs.append(max(a))
	a[i] = a2

for i in range(n):
	print(maxs[i])

Fixed submission:
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
max1 = max(a)
idx = a.index(max1)
a[idx] = 0
max2 = max(a)

for i in range(n):
	if i != idx:
		print(max1)
	else:
		print(max2)

Buggy python submission (verdict: Time Limit Exceeded):
import copy as c
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
maxs = []
for i in range(n):
	a2 = c.copy(a)
	a2[i] = 0
	maxs.append(max(a2))

for i in range(n):
	print(maxs[i])

Fixed submission:
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
max1 = max(a)
idx = a.index(max1)
a[idx] = 0
max2 = max(a)

for i in range(n):
	if i != idx:
		print(max1)
	else:
		print(max2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(max(d)):
	a = sum(x > i for x in d)
	if a == (n/2):
		ans += 1
print(ans)


Fixed submission:
n = int(input())
d = list(map(int, input().split()))
d.sort()
print(d[n//2]-d[(n//2)-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())

def zorome(n):
	l = []
	while n > 0:
		l.append(n%10)
		n = n//10
	return l

for i in range(n, 1000):
	ll = zorome(n)
	if ll[0] == ll[1] and ll[1] == ll[2]:
		break
	n += 1
print(n)

Fixed submission:
n,m,x,y = list(map(int, input().split()))
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

xs2 = sorted(xs)
ys2 = sorted(ys)
for i in range(x+1, y+1):
	if xs2[-1] < i <= ys2[0]:
		print("No War")
		quit()
print("War")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
dist = []
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dist.append(abs(a[i]-a[j]))
print(max(dist))

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

print(max(a)-min(a))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input) for i in range(n)]
dist = []
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dist.append(abs(a[i]-a[j]))
print(max(dist))

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

print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
line = input().split(' ')
a = int(line[0])
b = int(line[1])

axb_text = ''
for i in range(b):
    axb_text = f"{axb_text}{a}"

bxa_text = ''
for i in range(a):
    bxa_text = f"{bxa_text}{b}"

print(axb_text if axb_text < bxa_text else bxa_text)

Fixed submission:
line = input().split(' ')
a = int(line[0])
b = int(line[1])

axb_text = ''
for _ in range(b):
    axb_text += str(a)

bxa_text = ''
for _ in range(a):
    bxa_text += str(b)


print(axb_text if axb_text < bxa_text else bxa_text)

Buggy python submission (verdict: Runtime Error):
line = input().split(' ')
a = int(line[0])
b = int(line[1])

axb_text = ''
for _ in range(b):
    axb_text = f"{axb_text}{a}"

bxa_text = ''
for _ in range(a):
    bxa_text = f"{bxa_text}{b}"

print(axb_text if axb_text < bxa_text else bxa_text)

Fixed submission:
line = input().split(' ')
a = int(line[0])
b = int(line[1])

axb_text = ''
for _ in range(b):
    axb_text += str(a)

bxa_text = ''
for _ in range(a):
    bxa_text += str(b)


print(axb_text if axb_text < bxa_text else bxa_text)
Buggy python submission (verdict: Runtime Error):
# 足場は1~N 添え字は0~N-1
# 足場が1~Kまでのとき、dp[i+1]を求めるには、dp[j]+abs(h[i+1]-h[j]) 0<=j<=iの最小値を求める
# 1<=i+1<=Kのとき
# dp[1] = abs(h[1] - h[0])
# dp[K] dp[K-1]+abs(h[K]-h[K-1]), , ,dp[1]+abs(h[K]-h[1]), dp[0]+abs(h[K]-h[0])

# 足場がK+1~Nまでのとき(K+1<=i+1<=N-1のとき)
# dp[K+1] dp[K]+abs(h[K+1]-h[K]), , ,dp[1]+abs(h[K+1]-h[1])
# dp[N-1] dp[N-2]+abs(h[N-1]-h[N-2]), , ,dp[N-K-1]+abs(h[N-1]-h[N-K-1])
# dp[i+1]を求めるには、dp[j]+abs(h[i+1]-h[j]) i+1-K<=j<iの最小値を求める

# 初期化
# dp_jはdp[i+1]を求める際に使用する
dp = []
dp_j = []
for i in range(100001):
    dp.append(float('inf'))
for i in range(101):
    dp_j.append(float('inf'))

# 入力 添え字のN-1が足場Nに相当する
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp[0] = 0
for i in range(N - 1):
    if 0 <= i and i <= K - 1:
        for j in range(i + 1):
            dp_j[j] = dp[j] + abs(h[i + 1] - h[j])
        dp[i + 1] = min(dp_j)

    else:
        for j in range(i + 1 - K, i+1):
            dp_j[j] = dp[j] + abs(h[i + 1] - h[j])
        for j in range(i + 1 - K):
            dp_j[j] = float('inf')
        dp[i + 1] = min(dp_j)

print(dp[N - 1])

Fixed submission:
import numpy as np

# 足場は1~N 添え字は0~N-1
# 足場iの最小値は、min(dp[j]+abs(h[i]-h[j]))  min(0,i-K)<=j<=i-1<i
# 参照させてもらいました　https://harutech.hateblo.jp/entry/2019/02/10/202515　

# 入力 添え字のN-1が足場Nに相当する
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

# 初期化
dp = np.zeros(N, dtype=np.int)

dp[0] = 0
for i in range(1, N):
    start = max(0, i - K)
    dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i]))

print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
import numpy as np

# 入力
# 重さと価値はループのなかで都度取得する
N, W = map(int, input().strip().split())

# 初期化
dp = np.zeros(W + 1, dtype='int64')

# dpテーブル
for i in range(N):
    w, v = map(int, input().strip().split())
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)

print(dp[-1])

Fixed submission:
# dp[v] i番目までの品物で、価値がv以上になるよう選んだときの重さの最小値。
# 品物を増やすごとに、配列を更新して使いまわす。
# とれる価値の最大値VmaxはN*max(vi) 添え字は0<=v<=Vmax dpリストの長さはVmax+1
# ループは1~N回回す　添え字は0<=i<=N-1<N
# 解答はN回ループした後のdp[j]<=Wとなる最大のj

import numpy as np

# 入力 table[i][0]は重さ、table[i][1]は価値
N, W = map(int, input().strip().split())
t = []
for i in range(N):
    t.append(list(map(int, input().strip().split())))
table = np.array(t)

# 初期化 wiの最大値は10^9
Vmax = N * max(table[:, 1])
dp = np.full(Vmax + 1, 10 ** 9)
dp[0] = 0

# dp
for i in range(N):
    w = table[i][0]
    v = table[i][1]
    dp[v:] = np.minimum(dp[v:], dp[:-v] + w)

# 解答　dpの後ろから見て、最初にWを下回ったときのi
for j in range(Vmax, 0, -1):
    if dp[j] <= W:
        print(j)
        break
Buggy python submission (verdict: Runtime Error):
def main():
  array = []
  array = raw_input().split(' ')
  
  if sum(array) >= 22:
    print('bust')
  else:
    print('win')

if __name__ == '__main__':
  main()
  

Fixed submission:
#/usr/bin/env python3
def main():
  array = []
  array = list(map(int, input().split(' ')))
  
  if sum(array) >= 22:
    print('bust')
  else:
    print('win')

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
#!/bin/env python
  

if __name__=='__main__':
  val_n = input()
  list_v = list(map(int,input().split()))
  list_c = list(map(int,input().split()))

  answer = 0
  for i in range(len(list_v)):
    if(list_v[i] - list_c[i] > 0):
      answer += list_v[i] - list_c[i]
  print(answer)

Fixed submission:
#!/bin/env python
  
import sys

def validate(input):
    if input < 0 or input > 20:
        return False
    return True

def biscuitGen(input_a, input_b, input_t):
    biscuits = 0
    if validate(input_a) and validate(input_b) and validate(input_t):
        biscuits = int(input_t / input_a) * input_b
    return biscuits

if __name__=='__main__':
    '''
    print how many biscuit will be generated 
    A: Seconds to generate biscuit
    B: Number of biscuit pieces to generate once
    T: Limit of the seconds to generate biscuit
    1 <= A,B,T <= 20
    '''
    biscuit = 0
    inarray = list(map(int,input().split()))
    if len(inarray) != 3:
        print("Please input 3 numbers")
        sys.exit()
    biscuit = biscuitGen(inarray[0], inarray[1], inarray[2])
    print(biscuit)