Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def count_l(d,n):
	maxim = 0
	if n > 0:
		for t in wa_l(d,n-1):
			maxim = max(t[0]+d[t[1]],maxim)
	return(maxim)

def count_r(d,n):
	maxim = 0
	if n > 0:
		for t in wa_r(d,n-1):
			maxim = max(t[0]+d[N-1-t[1]],maxim)
	return(maxim)			
		

def wa_l(d,n):
	if n == 0:
		return([[0,0]])
	if n == 1:
		return([[d[0],1]])
	if n == 2:
		return([[0,1],[d[0]+d[1],2]])
	if n > 2:
		a = []
		for j in wa_l(d,n-2):
			j[1] += 1
			a.append(j)
		for j in wa_l(d,n-1):
			j[0] += d[j[1]]
			j[1] += 1
			a.append(j)
		return(a)

def wa_r(d,n):
	if n == 0:
		return([[0,0]])
	if n == 1:
		return([[d[N-1],1]])
	if n == 2:
		return([[0,1],[d[N-1]+d[N-2],2]])
	if n > 2:
		a = []
		for j in wa_r(d,n-2):
			j[1] += 1
			a.append(j)
		for j in wa_r(d,n-1):
			j[0] += d[N-1-j[1]]
			j[1] += 1
			a.append(j)
		return(a)

def l_r(d,n):
	maxim = 0
	for x in range(n+1):
		maxim = max(count_r(d,x)+count_l(d,n-x),maxim)
	print(maxim)

N, q= map(int,input().split())
p = list(map(int,input().split()))

l_r(p,q)

Fixed submission:
import sys
inputs = sys.stdin.readline
N, K= map(int,inputs().split())
V = list(map(int,inputs().split()))

maxim = 0
if K <= 2*N - 1:
	for i in range(0,K+1):
		for j in range(i+1):
			if j == i:
				a = V[:j] + [0]
			else:
				a = V[:j] + V[j-i:] + [0]
			a.sort()
			b = a.index(0)
			if b <= K - i:
				maxim = max(sum(a[b:]),maxim)
			else:
				maxim = max(sum(a[K-i:]),maxim)
else:
	V.append(0)
	V.sort()
	maxim = sum(V[V.index(0):])
print(maxim)
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
if a[0] <= 5:
  print(0)
elif a[0] <= 12:
  print(int(a[1]//2)
else:
  print(a[1])

Fixed submission:
a = list(map(int,input().split()))
if a[0] <= 5:
  print(0)
elif a[0] <= 12:
  print(a[1]//2)
else:
  print(a[1])

Buggy python submission (verdict: Runtime Error):
a = int(input().split())
if a[0] <= 5:
  print(0)
elif a[0] <= 12:
  print(a[1]/2)
else:
  print(a[0])

Fixed submission:
a = list(map(int,input().split()))
if a[0] <= 5:
  print(0)
elif a[0] <= 12:
  print(a[1]//2)
else:
  print(a[1])
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
min,max = map(int,input().split())
for k in range(m-1):
  a,b = map(int,input().split())
  if min < a:
    min = a
  if max > b:
    max = b
if b < a:
  print(0)
else:
  print(b-a+1)

Fixed submission:
max,m = map(int,input().split())
min = 1
for k in range(m):
  a,b = map(int,input().split())
  if min < a:
    min = a
  if max > b:
    max = b
if max < min:
  print(0)
else:
  print(max-min+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readline
N, M = map(int,inputs().split())
K = [None]*M
for t in range(M):
	x, y, z = map(int,inputs().split())
	K[t] = (x, y)
c = 0

U = [0]*(N+1)

for k in K:
	if U[k[0]] and U[k[1]]:
		a = U[k[0]]
		while(U[a] != a ):
			a = U[a]
		U[k[1]] = a
	elif U[k[1]]:
		U[k[0]] = U[k[1]]
	elif U[k[0]]:
		U[k[1]] = U[k[0]]
	else:
		U[k[0]] = k[0]
		U[k[1]] = k[0]

ans = 0
group = set()
for u in U[1:]:
	if u == 0:
		ans += 1
		continue
	elif u in group:
		group.add(u)
		continue
	elif u == U[u]:
		ans += 1
		group.add(u)
	else:
		while(u != U[u]):
			group.add(u)
		ans += 1
		group.add(u)
print(ans)

Fixed submission:
import sys
inputs = sys.stdin.readline
N, M = map(int,inputs().split())
K = [None]*M
for t in range(M):
	x, y, z = map(int,inputs().split())
	K[t] = (x, y)
c = 0

U = [0]*(N+1)

for k in K:
	if U[k[0]] and U[k[1]]:
		a = U[k[0]]
		b = U[k[1]]
		while(U[a] != a ):
			a = U[a]
		while(U[b] != b ):
			c = b
			b = U[b]
			U[c] = a
		U[b] = a
	elif U[k[1]]:
		U[k[0]] = U[k[1]]
	elif U[k[0]]:
		U[k[1]] = U[k[0]]
	else:
		U[k[0]] = k[0]
		U[k[1]] = k[0]

ans = 0
c = 0
group = set()
for n in range(1,N+1):
	if U[n] == 0:
		ans += 1
		continue
	elif n == U[n]:
		ans += 1
		group.add(U[n])
	elif U[n] in group:
		continue
	else:
		while(n != U[n] and U[n] not in group):
			group.add(U[n])
			n = U[n]
		group.add(U[n])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
inputs = sys.stdin.readline
N, M = map(int,inputs().split())
K = [None]*M
for t in range(M):
	x, y, z = map(int,inputs().split())
	K[t] = {x, y}
for p in range(M):
	for q in range(M - p -1):
		if K[q].isdisjoint(K[M - p - 1]) == False:
			K[q] = K[q] | K[M - p -1]
			K[M - p -1] = {0}
			continue
c = 0
for p in range(M):
	c += len(K[p]) - 1
print(N - c)

Fixed submission:
import sys
inputs = sys.stdin.readline
N, M = map(int,inputs().split())
K = [None]*M
for t in range(M):
	x, y, z = map(int,inputs().split())
	K[t] = (x, y)
c = 0

U = [0]*(N+1)

for k in K:
	if U[k[0]] and U[k[1]]:
		a = U[k[0]]
		b = U[k[1]]
		while(U[a] != a ):
			a = U[a]
		while(U[b] != b ):
			c = b
			b = U[b]
			U[c] = a
		U[b] = a
	elif U[k[1]]:
		U[k[0]] = U[k[1]]
	elif U[k[0]]:
		U[k[1]] = U[k[0]]
	else:
		U[k[0]] = k[0]
		U[k[1]] = k[0]

ans = 0
c = 0
group = set()
for n in range(1,N+1):
	if U[n] == 0:
		ans += 1
		continue
	elif n == U[n]:
		ans += 1
		group.add(U[n])
	elif U[n] in group:
		continue
	else:
		while(n != U[n] and U[n] not in group):
			group.add(U[n])
			n = U[n]
		group.add(U[n])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
S = int(S, 2)

a = 0
two = 2
b = 2**N -1
for n in range(N//2):
	a += two
	two *= 4
b = b^a
a = a ^ S
b = b ^ S
at = 0
bt = 0
for n in range(N):
	at += a%2
	bt += b%2
	a //= 2
	b //= 2
print(min(at, bt))

Fixed submission:
S = input()
N = len(S)
t0, t1 = 0, 1
a = 0
b = 0
for s in S:
	if s == "1":
		a += t0
	else:
		a += t1
	t0, t1 = t1, t0
print(min(a,N-a))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
S = int(S, 2)
a = ""
b = ""
for n in range(N):
	if n%2 ==0:
		a += '1'
		b += '0'
	else:
		a += '0'
		b += '1'
a = int(a, 2)
b = int(b, 2)
a = a ^ S
b = b ^ S
at = 0
bt = 0
for n in range(N):
	at += a%2
	bt += b%2
	a //= 2
	b //= 2
print(min(at, bt))

Fixed submission:
S = input()
N = len(S)
t0, t1 = 0, 1
a = 0
b = 0
for s in S:
	if s == "1":
		a += t0
	else:
		a += t1
	t0, t1 = t1, t0
print(min(a,N-a))
Buggy python submission (verdict: Runtime Error):
class A:

    def solve(self):
        [a, b, c] = sorted([int(x) for x in input().split(" ")])
        if a == 5 and b == 5 and c == 7:
            print("YES")
        else:
            print("NO")

class B:

    def solve(self):
        [n, l] = [int(x) for x in input().split(" ")]

        strings = []
        for r in range(n):
            strings.append(input())

        sorted_strings = sorted(strings)

        print("".join(sorted_strings))

class C:

    def solve(self):
        [n, k] = [int(x) for x in input().split(" ")]
        dislikes = [int(x) for x in input().split(" ")]

        likes = []
        for r in range(10):
            if r not in dislikes:
                likes.append(r)

        import bisect as b

        final_amount = []
        for c in str(n):
            i = b.bisect_left(likes, int(c))
            final_amount.append(str(likes[i]))

        print("".join(final_amount))

C().solve()


Fixed submission:
class A:

    def solve(self):
        [a, b, c] = sorted([int(x) for x in input().split(" ")])
        if a == 5 and b == 5 and c == 7:
            print("YES")
        else:
            print("NO")

class B:

    def solve(self):
        [n, l] = [int(x) for x in input().split(" ")]

        strings = []
        for r in range(n):
            strings.append(input())

        sorted_strings = sorted(strings)

        print("".join(sorted_strings))

class C:

    def fix(self, final_amount, likes):
        i = 0
        import bisect as b
        changed = False
        for i,x in enumerate(reversed(final_amount)):
            real_index = len(final_amount) - i - 1
            ind = b.bisect_right(likes, int(x))
            if ind != len(likes):
                final_amount[real_index] = str(likes[ind])
                changed = True
                break

        if not changed:
            ind = b.bisect_right(likes, 0)
            final_amount = [str(likes[ind])] + final_amount
            i = 1
        else:
            i = len(final_amount) - i - 1

        while i < len(final_amount):
            final_amount[i] = str(likes[0])
            i += 1

        return final_amount

    def solve(self):
        [n, k] = [int(x) for x in input().split(" ")]
        dislikes = [int(x) for x in input().split(" ")]

        likes = []
        for r in range(10):
            if r not in dislikes:
                likes.append(r)

        import bisect as b

        final_amount = []
        sn = str(n)
        for ind in range(len(sn)):
            c = sn[ind]
            i = b.bisect_left(likes, int(c))
            if i == len(likes):
                prev_len = len(final_amount)
                final_amount = self.fix(final_amount, likes)
                final_amount += [str(likes[0]) for r in range(len(sn) - prev_len)]
                break

            if str(c) != str(likes[i]):
                final_amount.append(str(likes[i]))
                final_amount += [str(likes[0]) for r in range(len(sn) - len(final_amount))]
                break

            final_amount.append(str(likes[i]))

        print("".join(final_amount))

C().solve()
Buggy python submission (verdict: Runtime Error):
S=list(input())
ans=0

for i in range(len(S)):
    if ans=0 and S[i]="R":
        ans=1
for i in range(len(S)-1):
    if S[i]=="R" and S[i+1]=="R":
        ans+=1

print(ans)



Fixed submission:
S=list(input())
ans=0

for i in range(len(S)):
    if ans==0 and S[i]=="R":
        ans=1
for i in range(len(S)-1):
    if S[i]=="R" and S[i+1]=="R":
        ans+=1

print(ans)

Buggy python submission (verdict: Runtime Error):
Slist=list(input())
ans=0

for i in range(len(S)):
    if ans=0 and S[i]="R":
        ans=1
for i in range(len(S)-1):
    if S[i]=="R" and S[i+1]=="R":
        ans+=1

print(ans)



Fixed submission:
S=list(input())
ans=0

for i in range(len(S)):
    if ans==0 and S[i]=="R":
        ans=1
for i in range(len(S)-1):
    if S[i]=="R" and S[i+1]=="R":
        ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X,K,D = map(int,input().split())
flag=False
for i in range(K):
    if X>0:
        X-=D
        if X<=0:
            if (K-i)%2==1:
                ans=abs(X)
                flag=True
                break
            else:
                ans=abs(X+D)
                flag=True
                break
    else:
        X+=D
        if X>=0:
            if (K-i)%2==1:
                ans=abs(X)
                flag=True
                break
            else:
                ans=abs(X-D)
                flag=True
                break
if flag == False:
    ans=abs(X)

print(ans)


Fixed submission:
X,K,D = map(int,input().split())
X=abs(X)
q=X//D
mod=X%D

if q <= K:
    if (K-q)%2==0:
        ans=mod
    else:
        ans=D-mod
else:
    ans=X-K*D
print(ans)
Buggy python submission (verdict: Runtime Error):




if __name__ == "__main__":
    n, m, x = map(int, input().split())

    c = []
    a = []

    for _ in range(n):
        cost, *rikaido = map(int, input().split())
        c.append(cost)
        a.append(rikaido)

    INF = float("inf")
    ans = INF
    
    for bit in range(1 << n):
        price_total = 0
        learn_total = [0] * m

        for i in range(n):
            if (bit >> i) & 1:
                # 買う場合
                price_total += c[i]
                for j in range(m):
                    learn_total[j] += a[i][j] 
        
        # 判定
        judge = True
        for j in range(m):
            if learn_total[j] < x:
                judge = False
                break
        
        if judge:
            ans = min(ans, price_total)
        
    if ans == INF:
        print(-1)
    else:
        print(ans)


Fixed submission:
S=input()
T=input()

if len(S)+1==len(T) and T.startswith(S):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s,w=map(int,input().split())
 
if s>w:
	return("safe")
else:
	return("unsafe")

Fixed submission:
s,w=map(int,input().split())
 
if s>w:
	print("safe")
else:
	print("unsafe")

Buggy python submission (verdict: Runtime Error):
s,w=map(int(),input().split())
 
if s>w:
	return("safe")
else:
	return("unsafe")

Fixed submission:
s,w=map(int,input().split())
 
if s>w:
	print("safe")
else:
	print("unsafe")

Buggy python submission (verdict: Runtime Error):
s,w=map(int(),input().split())
 
if s>w:
  print("safe")
else:
  print("unsafe")

Fixed submission:
s,w=map(int,input().split())
 
if s>w:
	print("safe")
else:
	print("unsafe")

Buggy python submission (verdict: Runtime Error):
s,w=map(int(),input().split())
 
if s>w:
  return("safe")
else:
  return("unsafe")

Fixed submission:
s,w=map(int,input().split())
 
if s>w:
	print("safe")
else:
	print("unsafe")

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

if s>w:
  return "safe"
else:
  return "unsafe"

Fixed submission:
s,w=map(int,input().split())
 
if s>w:
	print("safe")
else:
	print("unsafe")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(N-1):
    ans.append(A.count(i+1))
ans.append(0)
print("\n".join(list(map(str, ans))))

Fixed submission:
n = int(input())
 
boss_list = map(int, input().split())
 
employee_list = [0] * n
 
for boss in boss_list:
	employee_list[boss - 1] += 1
 
for employee in employee_list:
	print(employee)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(N-1):
    ans.append(A.count(i+1))
ans.append(0)
print("\n".join(list(map(str, ans))))

Fixed submission:
n = int(input())
 
boss_list = map(int, input().split())
 
employee_list = [0] * n
 
for boss in boss_list:
	employee_list[boss - 1] += 1
 
for employee in employee_list:
	print(employee)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(N-1):
    print(A.count(i+1))
print("0")

Fixed submission:
n = int(input())
 
boss_list = map(int, input().split())
 
employee_list = [0] * n
 
for boss in boss_list:
	employee_list[boss - 1] += 1
 
for employee in employee_list:
	print(employee)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(N-1):
    print(A.count(i+1))
print("0")


Fixed submission:
n = int(input())
 
boss_list = map(int, input().split())
 
employee_list = [0] * n
 
for boss in boss_list:
	employee_list[boss - 1] += 1
 
for employee in employee_list:
	print(employee)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def ggcd(*numbers):
    return reduce(math.gcd,numbers)

K=int(input())
sum=0


for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            sum+=ggcd(i,j,k)

print(sum)




Fixed submission:
import math
K=int(input())
sum=0
for i in range(1,K+1):
    for j in range(1,K+1):
        if math.gcd(i, j)==1:
            sum+=K
        else:
            g=math.gcd(i, j)
            for k in range(1,K+1):
                sum += math.gcd(g,k)
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
cnt=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            A=[i,j,k]
            m=0
            for l in range(N):
                #print("i,j,k,l,m,cnt",i,j,k,l,m,cnt)
                if int(S[l]) == A[m]:
                    m += 1
                if m == 3:
                    cnt += 1
                    break

print(cnt)





Fixed submission:
N = int(input())
S = input()
cnt=0
for i in range(10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b=S.find(str(j),a+1)
        if b == -1:
            continue
        for k in range(10):
            c=S.find(str(k),b+1)
            if c != -1:
                cnt+=1
            

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())
cnt=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            A=[i,j,k]
            m=0
            for l in range(N):
                #print("i,j,k,l,m,cnt",i,j,k,l,m,cnt)
                if int(S[l]) == A[m]:
                    m += 1
                if m == 3:
                    cnt += 1
                    break

print(cnt)





Fixed submission:
N = int(input())
S = input()
cnt=0
for i in range(10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b=S.find(str(j),a+1)
        if b == -1:
            continue
        for k in range(10):
            c=S.find(str(k),b+1)
            if c != -1:
                cnt+=1
            

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=list(map(int,input().split()))

for i in range(M):
    A[A.index(max(A))]=A[A.index(max(A))]//2
print(sum(A))



Fixed submission:
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)

ans = 0
for i in range(M):
    most_expensive = -heapq.heappop(A)
    most_expensive //= 2
    heapq.heappush(A, -most_expensive)

print(-sum(A))
Buggy python submission (verdict: Runtime Error):
N=int(input())
print(N(N-1)//2)

Fixed submission:
N=int(input())
print(N*(N-1)//2)

Buggy python submission (verdict: Runtime Error):
S=int(input())

print(N(N-1)//2)

Fixed submission:
N=int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
Sa=[1]*len(S)
if len(S)%2 != 0:
    turn=len(S)+1
else:
    turn=len(S)

for i in range(turn):#iターン目。
    Sb=[0]*len(S) 
    for j in range(len(S)):#j番目の順列
        if j == 0:
            if S[j+1]=='L':
                Sb[j]=Sa[j+1]
        elif j==len(S)-1:
            if S[j-1]=='R':
                Sb[j]=Sa[j-1]
        else:
            if S[j-1]=='R':
                Sb[j] = Sb[j]+Sa[j-1]
            if S[j+1]=='L':
                Sb[j] = Sb[j]+Sa[j+1]
    Sa=Sb
print(" ".join(str(n) for n in Sa))



Fixed submission:
li=input()
n=len(li)
child_li=[0]*n



ruiseki=0
for i in range(n-1):
    if li[i]=='R':
        ruiseki+=1
        if li[i+1]=='L':
            child_li[i+1]=ruiseki//2
            child_li[i]=(ruiseki+1)//2
    else:
        ruiseki=0


ruiseki=0
for i in range(n-1, 0, -1):
    if li[i]=='L':
        ruiseki+=1
        if li[i-1]=='R':
            child_li[i-1]+=ruiseki//2
            child_li[i]+=(ruiseki+1)//2
    else:
        ruiseki=0

print(*child_li)
Buggy python submission (verdict: Runtime Error):
import collections

N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[]
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1:
            L.append(j-i)
        elif j-i == 1:
            L.append(1)
        elif i <= X-1 and j >= Y-1:
            L.append(1+abs(X-1-i)+abs(Y-1-j))
        elif i >= X-1 and i-(X-1) > (Y-1)-i:
            L.append(j-i)            
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L.append(min(L1,L2))

c=collections.Counter(L)

for i in range(1,N):
    print(c[i])




Fixed submission:
import numpy as np
import collections

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

a=np.array(A, dtype=np.float64)
asign=np.sign(A)
c = collections.Counter(asign)
ar = np.array(c[-1], dtype=np.float64)
ac = a * asign

if c[-1] % 2 == 0:
    print(int(sum(ac)))
else:
    print(int(sum(ac)-min(ac)*2))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+1)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])




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

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+K+1)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])




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

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+K+1)
dp[0]=0
for i in range(N):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])




Fixed submission:
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+1)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+1)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])

Fixed submission:
N=int(input())
a=[0]*N
b=[0]*N
c=[0]*N
hpa=[0]*N
hpb=[0]*N
hpc=[0]*N
hp=[0]*N

for i in range(N):
    a[i],b[i],c[i]=map(int,input().split())

hpa[0]=a[0]
hpb[0]=b[0]
hpc[0]=c[0]
hp[0]=max(hpa[0],hpb[0],hpc[0])

for i in range(N-1):
    hpa[i+1]=max(hpb[i]+a[i+1],hpc[i]+a[i+1])
    hpb[i+1]=max(hpa[i]+b[i+1],hpc[i]+b[i+1])
    hpc[i+1]=max(hpa[i]+c[i+1],hpb[i]+c[i+1])
    hp[i+1]=max(hpa[i+1],hpb[i+1],hpc[i+1])

print(hp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())

#dp[i][j]は、品数i,重さjのときの価値
dp =[[0 for i in range(W+1)] for j in range(N+1)] 
#表で表す

for i in range(N):#これは品数.i番目の品のオンオフ
    for j in range(W+1):#これは許容される重さの合計
        #選ぶ場合
        if j - w[i]>=0:
            dp[i+1][j]=max(dp[i][j],(dp[i][j-w[i]]+v[i]))
        #選ばない場合と比較
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])

print(dp[N][W])

Fixed submission:
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())

#dp[i][j]は、品数i,重さjのときの価値
dp =[[0 for i in range(W+1)] for j in range(N+1)] 
#表で表す

for i in range(N):#これは品数.i番目の品のオンオフ
    for j in range(W+1):#これは許容される重さの合計
        #選ぶ場合
        if j - w[i]>=0:
            dp[i+1][j]=max(dp[i][j],(dp[i][j-w[i]]+v[i]))
        #選ばない場合と比較
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])

print(dp[N][W])

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*(N+1)
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j>N-1:
            break
        else:
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])
 

Fixed submission:
N,W=map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i]=map(int,input().split())

#dp[i][j]は、品数i,重さjのときの価値
dp =[[0 for i in range(W+1)] for j in range(N+1)] 
#表で表す

for i in range(N):#これは品数.i番目の品のオンオフ
    for j in range(W+1):#これは許容される重さの合計
        #選ぶ場合
        if j - w[i]>=0:
            dp[i+1][j]=max(dp[i][j],(dp[i][j-w[i]]+v[i]))
        #選ばない場合と比較
        dp[i+1][j]=max(dp[i][j],dp[i+1][j])

print(dp[N][W])