Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
cnt = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        if  (N - r*R - g*G) < 0:
            break
        if  (N - r*R - g*G)%B == 0 :
            cnt +=1
            #print(r,g,(N - r*R - g*G)//B)
print(cnt)

Fixed submission:
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(N+1):
    for g in range(N+1):
        if  (N - r*R - g*G) >= 0 and  (N - r*R - g*G)%B == 0 :
            cnt +=1
            #print(r,g,(N - r*R - g*G)//B)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        if  (N - r*R - g*G) >= 0 and  (N - r*R - g*G)%B == 0 :
            cnt +=1
            #print(r,g,(N - r*R - g*G)//B)
print(cnt)

Fixed submission:
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(N+1):
    for g in range(N+1):
        if  (N - r*R - g*G) >= 0 and  (N - r*R - g*G)%B == 0 :
            cnt +=1
            #print(r,g,(N - r*R - g*G)//B)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(N+1):
    for g in range(N+1):
        if  (N - r*R - g*G) >= 0 and  (N - r*R - g*G)%B == 0 :
            cnt +=1
            #print(r,g,(N - r*R - g*G)//B)
print(cnt)

Fixed submission:
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(N+1):
    for g in range(N+1):
        if  (N - r*R - g*G) >= 0 and  (N - r*R - g*G)%B == 0 :
            cnt +=1
            #print(r,g,(N - r*R - g*G)//B)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
n = int(input())
L = list(map(int,input().split()))
def GCD1(a,b):
    return gcd(a,b)
def GCD2(L):
    return reduce(GCD1,L)

liL = [0]*(n)
liR = [0]*(n)
for i in range(1,n+1):
    if len(L[:i-1]) == 0:
        liL[i-1] = 0
        liR[i-1] = (GCD2(L[i:]))
    elif len(L[i:]) == 0:
        liR[i-1] = 0
        liL[i-1] = (GCD2(L[:i-1]))
    else:
        liL[i-1] = (GCD2(L[:i-1]))
        liR[i-1] = (GCD2(L[i:]))
    #print(L[:i-1],L[i:])
    #print(liL,liR)
#print(liL,liR)
ans = 0
for a,b in zip(liL,liR):
    ans = max(ans,GCD1(a,b))
print(ans)

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

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n):
    l[i+1] = gcd(l[i],L1[i])
    r[n-(i+1)] = gcd(r[n-i],L1[n-(i+1)])

ans = 0
for i in range(n):
    ans = max(ans,gcd(l[i],r[i+1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int,input().split()))

def sel2(a,b,c):
    if a <= 0 and b <= 0 and c >= 0:
        return (-a,-b,c)
    elif a >= 0 and b <= 0 and c <= 0:
        return (a,-b,-c)
    elif a <= 0 and b >= 0 and c <= 0:
        return (-a,b,-c)
def sel1(a,b,c):
    if a <= 0 and b >= 0 and c >= 0:
        if abs(a) >= abs(b):
            return (-a,-b,c)
        else:
            return (a,b,c)
    elif a >= 0 and b <= 0 and c >= 0:
        if abs(b) == min(abs(a),abs(b),abs(c)):
            return (a,b,c)
        elif abs(a) > abs(c):
            return (a,-b,-c)
        elif abs(a) < abs(b):
            return (-a,-b,c)
    elif a >= 0 and b >= 0 and c <= 0:
        if abs(b) >= abs(c):
            return (a,-b,-c)
        else:
            return (a,b,c)
def selend(a,b):
    if a < 0 and b < 0:
        return (-a,-b)
    elif a < 0 and b > 0:
        if abs(a) > abs(b):
            return (-a,-b)
        elif abs(a) < abs(b):
            return (a,b)
    elif a > 0 and b < 0:
        if abs(a) > abs(b):
            return (a,b)
        elif abs(a) < abs(b):
            return (-a,-b)
for i in range(0,n//3+1,3):
    (p,q,r) = sel2(L[i],L[i+1],L[i+2])
    L[i] = p
    L[i+1] = q
    L[i+2] = r
#print(L)
(s,t) = selend(L[-2],L[-1])
L[-2] = s
L[-1] = t
#print(L)
print(sum(L))

Fixed submission:
n = int(input())
L = list(map(int,input().split()))
L1 = len([x for x in L if x < 0])
L.sort()
for i in range(n):
  if L[i] < 0:
    L[i] = -L[i]
#print(L)
if L1%2 == 0:
  print(sum(L))
else:
  print(sum(L)-2*min(L))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()
zero,one = [],[]
cnt = 0
if s[0] == "0":
    flag = True
else:
    flag = False
for i in range(n-1):
    if s[i] == "0" and flag == True:
        cnt +=1
        if s[i] == "0" and s[i+1] =="1":
            zero.append(cnt)
            flag = False
            cnt = 0
    elif s[i] == "1" and flag == False:
        cnt +=1
        if s[i+1] =="0":
            one.append(cnt)
            flag = True
            cnt = 0
    else:
        cnt +=1
        
    if i == n-2:
        if s[i+1] == "0":
            cnt +=1
            zero.append(cnt)
        elif s[i+1] == "1":
            cnt +=1
            one.append(cnt)
            
sum1 = sum(zero[:k]) + sum(one[:k+1])
ans = sum1
#print(sum1,ans,len(zero),zero,one)
if k >= len(zero):
    print(n)
    exit()
else:
    if s[0] == "1":
        for i in range(1,len(zero)-k):
            #print(sum1)
            sum1 -=(zero[i] + one[i])
            sum1 +=(zero[i+k] + one[i+k+1])
            ans = max(ans,sum1)
            #print(sum1,ans)
    elif s[0] =="0":
        print(sum1,ans)
        for i in range(1,len(zero)-k):
            sum1 -=(zero[i] + one[i])
            
            sum1 +=(zero[i+k] + one[i+k])
            ans = max(ans,sum1)
            
print(ans)

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

L = []
from itertools import groupby
for key ,value in groupby(s):
    L.append((key,len(list(value))))
#print(L)
c = []
for i in range(len(L)):
    c.append(L[i][1])
c = [0] + c

for i in range(1,len(c)):
    c[i] +=c[i-1]
#print(c)
l = 0 
r = 2*k

ans = 0
while True:
    if L[l][0] == "1":
        if l + r +1 < len(L):
            ans = max(ans,c[l+r+1] - c[l])#add 5
        else:
            ans = max(ans,c[len(L)] - c[l])
    elif L[l][0] == "0":
        if l + r < len(L):
            ans = max(ans,c[l+r] - c[l])#add 4
        else:
            ans = max(ans,c[len(L)] - c[l])
    if l == len(L)-1:
        break
    l +=1
print(ans)
Buggy python submission (verdict: Runtime Error):
X,Y,Z,K = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
     
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
     
li = []
for i in range(len(a)):
    for j in range(len(b)):
        li.append(a[i]+b[j])
    
li.sort(reverse = True)
     
li1 = []
for i in range(len(li)):
    for j in range(len(c)):
        li1.append(li[i]+c[j])
        if j > k:
          break
li1.sort(reverse = True)
n = 1
while n < K+1:
    print(li1[n-1])
    n += 1

Fixed submission:
li = list(int(input()) for i in range(5))
#print(li)
k = int(input())

li1 = [(x - y) for x in li for y in li if x>y]
#print(li1)
if all(li1[i]<=k for i in range(len(li1))):
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
L = [int(input()) for i in range(5)]
L1 = [x for x in L if x%10 ==0 ]
L2 = [x for x in L if x%10 !=0 ]
L3 = [x%10 for x in L2 ]

idx = L3.index(min(L3))
for i in range(len(L2)):
    if i != idx:
        L2[i] = (L2[i]//10+1)*10
if L1:
    a = sum(L1)
else:
    a =0
if L2:
    b = sum(L2)
else:
    b = 0
print(a+b)

Fixed submission:
L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
if len(L3)>0:
  L3.sort(reverse = True)
  for i in range(len(L3)-1):
    ans += (L3[i][1]+1)*10
  ans += L3[-1][1]*10+L3[-1][0]
print(ans)

Buggy python submission (verdict: Runtime Error):
L = [int(input()) for i in range(5)]
L1 = [x for x in L if x%10 ==0 ]
L2 = [x for x in L if x%10 !=0 ]
L3 = [x%10 for x in L2 ]

idx = L3.index(min(L3))
for i in range(len(L2)):
    if i != idx:
        L2[i] = (L2[i]//10+1)*10

print(sum(L1)+sum(L2))

Fixed submission:
L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
if len(L3)>0:
  L3.sort(reverse = True)
  for i in range(len(L3)-1):
    ans += (L3[i][1]+1)*10
  ans += L3[-1][1]*10+L3[-1][0]
print(ans)

Buggy python submission (verdict: Runtime Error):
L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
if len(L3)>0:
	L3.sort(reverse = True)
	for i in range(len(L3)-1):
    	ans += (L3[i][1]+1)*10
	ans += L3[-1][1]*10+L3[-1][0]
print(ans) 

Fixed submission:
L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
if len(L3)>0:
  L3.sort(reverse = True)
  for i in range(len(L3)-1):
    ans += (L3[i][1]+1)*10
  ans += L3[-1][1]*10+L3[-1][0]
print(ans)

Buggy python submission (verdict: Runtime Error):
L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
L3.sort(reverse = True)

for i in range(len(L3)-1):
    ans += (L3[i][1]+1)*10
ans += L3[-1][1]*10+L3[-1][0]
print(ans) 

Fixed submission:
L = []
for i in range(5):
    L.append(int(input()))

L1 = [x for x in L if x%10 == 0]
L2 = [x for x in L if x%10 != 0]
L3 = [(x%10,x//10) for x in L2]

ans = sum(L1)
if len(L3)>0:
  L3.sort(reverse = True)
  for i in range(len(L3)-1):
    ans += (L3[i][1]+1)*10
  ans += L3[-1][1]*10+L3[-1][0]
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
i=0
li = []
num = 0
while i<=len(s)-1:
    
    s1 = ["A","C","G","T"]
    
    if s[i] in s1 :
        num += 1
        i += 1
        li.append(num)
    elif s[i] not in s1 :
        num = 0
        i += 1
        
print(max(li))

Fixed submission:
s = list(input())
i=0
li = [0]
num = 0
while i<=len(s)-1:
    
    s1 = ["A","C","G","T"]
    
    if s[i] in s1 :
        num += 1
        i += 1
        li.append(num)
    elif s[i] not in s1 :
        num = 0
        i += 1
        
print(max(li))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
s = list(input())
li = [0]*(a+1)
for i in range(a):
    if s[i] == "A":
        if s[i+1] == "C":
            li[i+1]  = 1

li2 = [0]*(a+1)
li2[0] = li[0]
for i in range(1,len(li)):
    li2[i] = li2[i-1]+li[i]

for i in range(b):
    l,r = map(int,input().split())
    #print(l,r)
    print(li2[r-1]-li2[l-1])

Fixed submission:
from itertools import accumulate
n,q = map(int,input().split())
s = input()
L = [0]*n

for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        L[i] = 0
        L[i+1] = 1

LL = list(accumulate(L))
for i in range(q):
    l,r = map(int,input().split())
    print(LL[r-1]-LL[l-1])

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

s=input()
s=list(s)
li =[]

for i in range(n):
    a,b = map(int,input().split())
    num=0
    for j  in range(a-1,b-1):
        #print(j)
        
        if s[j]=="A" and s[j+1] == "C":
            num+=1
            
    li.append(num)
for i in range(len(li)):
    print(li[i])

Fixed submission:
from itertools import accumulate
n,q = map(int,input().split())
s = input()
L = [0]*n

for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        L[i] = 0
        L[i+1] = 1

LL = list(accumulate(L))
for i in range(q):
    l,r = map(int,input().split())
    print(LL[r-1]-LL[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M = (map(int, input().split()))
li = [list(map(int,input().split())) for i in range(N)]

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])

print(sum(li3[0:M]))

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

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])
    if len(li3)>M:
        break
print(sum(li3[0:M]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = (map(int, input().split()))
li = list((input().split()) for i in range(N))
for x in range(len(li)):
    li[x] = [int(i) for i in li[x]]
 
li.sort()
#print(li)
li2=[]
#for i in range(len(li)):
#    li2.append(li[i][0]*li[i][1])
#print(li2)
li3 = []
for j in range(len(li)):
    for i in range(li[j][1]):
        li3.append(li[j][0])
#print(li3)
print(sum(li3[0:M]))

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

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])
    if len(li3)>M:
        break
print(sum(li3[0:M]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = (map(int, input().split()))
li = list((input().split()) for i in range(N))
for x in range(len(li)):
    li[x] = [int(i) for i in li[x]]

li.sort()

li2=[]
for i in range(len(li)):
    li2.append(li[i][0]*li[i][1])

li3 = []
for j in range(len(li)):
    for i in range(li[j][1]):
        li3.append(li[j][0])

print(sum(li3[0:M]))

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

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])
    if len(li3)>M:
        break
print(sum(li3[0:M]))
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int,input().split())
li = []
li2 = [0]*(len(list(bin(b))[2:]))

for i in range(a,b+1):
    li.append(list(bin(i))[2:][::-1])
for i in range(len(li)):
    for j in range(len(li[i])):
        li2[j] += int(li[i][j])

li3 = []
for i in range(len(li2)):
    if li2[i]%2 == 1:
        li3.append("1")
    else:
        li3.append("0")
li3 = ("".join(li3))[::-1]

print(int(li3,2))

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

mid_xor = 0
if a%2 == 0 and b%2 == 1:
    even_cnt = (b-a+1)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(mid_xor)

elif a%2 == 1 and b%2 == 0:
    even_cnt = (b-1-(a+1)+1)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(a^mid_xor^b)

elif a%2 == 0 and b%2 == 0:
    even_cnt = (b-a)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(mid_xor^b)
    
elif a%2 == 1 and b%2 == 1:
    even_cnt = (b-a)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(a^mid_xor)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
def w(a,b):
    li=[]
    d = max(a,b)
    for i in range(1,d//2+1):
        if a%(i) == 0 and b%(i)==0:
            li.append(i)
    #print(li)
    print(li[-c])
w(a,b)

Fixed submission:
a,b,c = map(int,input().split())
if b>=a*c:
  print(c)
else:
  print(b//a)
Buggy python submission (verdict: Runtime Error):
a,b ,k = map(int,input().split())
cnt = 0
for i in range(1,min(a,b)+1):
  if a%i == 0 and b%i == 0:
    cnt +=1
 	if cnt == k:
      print(i)
      exit()


Fixed submission:
a,b,k = map(int,input().split())
c = []
for i in range(min(a,b)+1):
  if a%(i+1) == 0 and b%(i+1) == 0:
    c.append(i+1)
c.sort(reverse = True)
print(c[k-1])

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int,input().split())
c = []
for i in range(max(a,b)//2):
  if a%(i+1) == 0 and b%(i+1) == 0:
    c.append(i+1)
c.sort(reverse = True)
print(c[k-1])

Fixed submission:
a,b,k = map(int,input().split())
c = []
for i in range(min(a,b)+1):
  if a%(i+1) == 0 and b%(i+1) == 0:
    c.append(i+1)
c.sort(reverse = True)
print(c[k-1])

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
def w(a,b):
    li=[]
    d = max(a,b)
    for i in range(d//2):
        if a%(i+1) == 0 and b%(i+1)==0:
            li.append(i+1)
    #print(li)
    print(li[c-1])
w(a,b)

Fixed submission:
a,b,k = map(int,input().split())
c = []
for i in range(min(a,b)+1):
  if a%(i+1) == 0 and b%(i+1) == 0:
    c.append(i+1)
c.sort(reverse = True)
print(c[k-1])
Buggy python submission (verdict: Runtime Error):
s = list(input())
if s[7] <= 3 or (s[7] == 4 and s[8] <=3):
  print("Heisei")
else:
  print("TBD")

Fixed submission:
n = input()
n1 = int(n[0:4]+n[5:7]+n[8:10])
if n1 > 20190430:
    print("TBD")
else:
    print("Heisei")
Buggy python submission (verdict: Runtime Error):
from  math import gcd
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(gcd,li))

Fixed submission:
from fractions import gcd
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(gcd,li))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(math.gcd,li))

Fixed submission:
from fractions import gcd
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(gcd,li))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
n = int(input())
li = list(map(int,input().split())
print(reduce(math.gcd,li))


Fixed submission:
from fractions import gcd
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(gcd,li))

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

while len(li)>1:
    li.sort()
    li[-1] = li[-1]%li[0]
    if li[-1] == 0:
        li.pop()
print(li[0])

Fixed submission:
from fractions import gcd
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(gcd,li))
Buggy python submission (verdict: Runtime Error):
n = int(input())
L = []
for i in range(n):
    L.append(input())

def num(a,b,c):
    s = {a,b,c}
    return len(s)-1
cnt = 0
for i in range(n):
    cnt += num(L[0][i],L[1][i],L[2][i])
print(cnt)


Fixed submission:
n = int(input())
L = []
for i in range(3):
    L.append(input())

cnt = 0
for i in range(n):
    s = set((L[0][i],L[1][i],L[2][i]))
    cnt += len(s)-1
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
L = []
for i in range(n):
    L.append(input())

def num(a,b,c):
    s = {a,b,c}
    return len(s)-1
cnt = 0
for i in range(n):
    cnt += num(L[0][i],L[1][i],L[2][i])
print(cnt)


Fixed submission:
n = int(input())
L = []
for i in range(3):
    L.append(input())

cnt = 0
for i in range(n):
    s = set((L[0][i],L[1][i],L[2][i]))
    cnt += len(s)-1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n ,k= map(int,input().split())
h = list(map(int,input().split()))
#print(h)
inf = float("inf")
dp = [inf]*(n+1)
dp[0] = 0


for i in range(1,n):
    for j in range(1,k+1):
        if i-j >=0:
            dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))
            #print(dp)
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(n)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(n)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(n)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(n-1)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(n)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(100)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
L = list(map(int,input().split()))
dp = [float("inf")]*(n)
dp[0] = 0

for i in range(1,n):
    for j in range(max(0,i-k),i):
        dp[i] = min(dp[i],dp[j]+abs(L[i]-L[j]))
        
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    
    N,W = map(int,input().split())
    w,v = [],[]
    for i in range(N):
        a,b = map(int,input().split())
        w.append(a)
        v.append(b)
    dp = [[0]*(W+1) for i in range(N+1)]

    for i in range(N):
        for j in range(W+1):
            if j-w[i] >= 0:
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j])
            else:
                dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    #print(dp)
    print(dp[N][W])

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    
    N,W = map(int,input().split())
    w,v = [],[]
    for i in range(N):
        a,b = map(int,input().split())
        w.append(a)
        v.append(b)
    dp = [[0]*(W+1) for i in range(N+1)]

    for i in range(N):
        for j in range(W+1):
            if j-w[i] >= 0:
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j])
            else:
                dp[i+1][j] = max(dp[i+1][j], dp[i][j])
    #print(dp)
    print(dp[N][W])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w,v = [],[]
for i in range(N):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
m = sum(v)
dp = [[0]*(m+1) for i in range(N+1)]

for i in range(N):
    for j in range(m+1):
        if j-v[i] >=0:
            dp[i+1][j] = max(dp[i][j-v[i]] + w[i],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

for j in range(m+1):
        if dp[N][j] <= W:
            ans = max(ans,j)
print(ans)

Fixed submission:
N,W = map(int,input().split())
w,v = [],[]
for i in range(N):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
m = sum(v)
dp=[[float("inf")]*(m+1) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(m+1):
        if j-v[i] >=0:
            dp[i+1][j] = min(dp[i][j-v[i]] + w[i],dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
ans = 0
for j in range(m+1):
        if dp[N][j] <= W:
            ans = max(ans,j)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())

if n == 1:
    print(m)
    exit()
    
if n >= len(L):
    print(1)
    exit()
    
div = 2
L = []
i = 1
while div <= int(m**0.5)+1:
    while m%div == 0:
        m //=div
        L.append(div)
    div +=1
L.append(m)
#print(L)

from collections import Counter
L = Counter(L)

cnt = 1
for k,v in L.items():
    if v >= n:
        cnt *=k
print(cnt)

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

div = 2
L = []
i = 1
while div <= int(m**0.5)+1:
    while m%div == 0:
        m //=div
        L.append(div)
    div +=1
if m!= 1:
    L.append(m)
#L.append(1)

from collections import Counter
L = Counter(L)

cnt = 1
for k,v in L.items():
    cnt *=k**(v//n)
print(cnt)
Buggy python submission (verdict: Runtime Error):
n, k = map(int,input().split())
li = list(int(input()) for i in range(n))

li.sort()
num = 0
li2 = []
for i in range(len(li)-k+1):
    li2.append( max(li[i:i+k]) - min(li[i:i+k]))

print(min(li2))

Fixed submission:
n = int(input())
if n == 25:
    print("Christmas") 
elif n == 24:
    print("Christmas Eve")
elif n == 23:
    print("Christmas Eve Eve")
elif n == 22:
    print("Christmas Eve Eve Eve")