Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())

li = [r, g, b]
li.sort(reverse=True)

num_max_0 = n//li[0]
num_max_1 = n//li[1]
ans = 0
for num_0 in range(num_max_0 + 1):
    for num_1 in range(num_max_1 + 1):
        ball_2 = n - num_0*li[0] - num_1*li[1]
        if ball_2 >= 0 and ball_2 % li[2] == 0:
            ans += 1
print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())

num_max_r = n//r

ans = 0
for num_r in range(num_max_r + 1):
    
    n_r = n - num_r*r
    num_max_g = n_r//g
    
    for num_g in range(num_max_g + 1):
        n_r_g = n_r - num_g*g
        
        if n_r_g >= 0 and n_r_g % b == 0:
            ans += 1

print(ans)

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

li = [r, g, b]
li.sort(reverse=True)

num_max_0 = n//li[0]
num_max_1 = n//li[1]
ans = 0
for num_0 in range(num_max_0 + 1):
    for num_1 in range(num_max_1 + 1):
        ball_01 = num_0*li[0] + num_1*li[1]
        ball_2 = n - ball_01

        if ball_2 >= 0 and ball_2 % li[2] == 0:
            ans += 1
print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())

num_max_r = n//r

ans = 0
for num_r in range(num_max_r + 1):
    
    n_r = n - num_r*r
    num_max_g = n_r//g
    
    for num_g in range(num_max_g + 1):
        n_r_g = n_r - num_g*g
        
        if n_r_g >= 0 and n_r_g % b == 0:
            ans += 1

print(ans)

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

li = [r, g, b]
li.sort(reverse=True)

num_max_0 = n//li[0]
num_max_1 = n//li[1]

ans = 0
for num_0 in range(num_max_0 + 1):
    for num_1 in range(num_max_1 + 1):
        ball_01 = num_0*li[0] + num_1*li[1]
        ball_2 = n - ball_01
        
        if ball_2 >= 0 and ball_2 % li[2] == 0:
            ans += 1

print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())

num_max_r = n//r

ans = 0
for num_r in range(num_max_r + 1):
    
    n_r = n - num_r*r
    num_max_g = n_r//g
    
    for num_g in range(num_max_g + 1):
        n_r_g = n_r - num_g*g
        
        if n_r_g >= 0 and n_r_g % b == 0:
            ans += 1

print(ans)

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

num_max_r = n//r
num_max_g = n//g

ans = 0
for num_r in range(num_max_r + 1):
    for num_g in range(num_max_g + 1):
        ball_rg = num_r*r + num_g*g
        ball_b = n - ball_rg
        
        if ball_b >= 0 and ball_b % b == 0:
            ans += 1

print(ans)

Fixed submission:
r, g, b, n = map(int, input().split())

num_max_r = n//r

ans = 0
for num_r in range(num_max_r + 1):
    
    n_r = n - num_r*r
    num_max_g = n_r//g
    
    for num_g in range(num_max_g + 1):
        n_r_g = n_r - num_g*g
        
        if n_r_g >= 0 and n_r_g % b == 0:
            ans += 1

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

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())



ans = 0
for i in [a, b, c, d, e]:
    ans += int(math.ceil(i/10)*10)

li = [int(str(a)[-1]), int(str(b)[-1]), int(str(c)[-1]), int(str(d)[-1]), int(str(e)[-1])]
while 0 in li:
    li.remove(0)

ans = ans + min(li) - 10
    
print(ans)

Fixed submission:
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())



ans = 0
for i in [a, b, c, d, e]:
    ans += int(math.ceil(i/10)*10)

    
li = [int(str(a)[-1]), int(str(b)[-1]), int(str(c)[-1]), int(str(d)[-1]), int(str(e)[-1])]

if li == [0, 0, 0, 0, 0]:
    ans = ans + min(li)
    print(ans)
    
else:
    for j in li:
        if j==0:
            li.remove(0)
    ans = ans + min(li) - 10
    print(ans)
Buggy python submission (verdict: Runtime Error):
abc = list(map(int, input.split()))
if len(set(abc)) == 1:
    print('Yes')
else:
    print('No')


Fixed submission:
abc = list(map(int, input().split()))
if len(set(abc)) == 1:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

ans = 0
for b in B:
    ans += sum(A < b) * sum(C > b)
print(ans)

Fixed submission:
import numpy as np
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
A = list(map(int, input().split()))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

ans = 0
for a in A:
    for b in list(B[B>a]):
        ans += sum(C>b)
        
print(ans)

Fixed submission:
import numpy as np
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

ans = 0
for a in A:
    for b in B[B>a]:
        ans += sum(C>b)
        
print(ans)

Fixed submission:
import numpy as np
import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = list(map(int, input().split()))

ans = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                ans += 1

print(ans)

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

ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            ans += 1

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


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


A, B, C, D = map(int, input().split())

# B以下で割り切れる
UB_C = B // C
UB_D = B // D
UB_CD = B // lcm(C, D)

UB = B - (UB_C + UB_D - UB_CD)

# A以下で割り切れる
UA_C = A // C
UA_D = A // D
UA_CD = A // lcm(C, D)

UA = A - (UA_C + UA_D - UA_CD)

ans = UB - UA

if A % C != 0 and A % D != 0:
    ans += 1

print(ans)


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


def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B, C, D = map(int, input().split())

# B以下で割り切れる
UB_C = B // C
UB_D = B // D
UB_CD = B // lcm(C, D)

UB = B - (UB_C + UB_D - UB_CD)

# A以下で割り切れる
UA_C = A // C
UA_D = A // D
UA_CD = A // lcm(C, D)

UA = A - (UA_C + UA_D - UA_CD)

ans = UB - UA

if A % C != 0 and A % D != 0:
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import pandas as pd
from pandas import Series

N = int(input())
A = [int(input()) for _ in range(N)]
# 一番でかいやつと二番目のやつを見つける。
# 1番でかいやつが１つなら、基本最大値で、そいつがえらばれたら2番目の値教える。

max_val = max(A)
if sum(Series(A) == max_val) > 1:
    for i in range(0,N):
        print(max_val)
else:
    max_val_index = A.index(max_val)
    A[max_val_index] = 0
    sec_max_val = max(A)
    for i in range(0,N):
        if i == max_val_index:
            print(sec_max_val)
        else:
            print(max_val)
            
# 一番でかいやつが２つ以上いるなら、つねに1番の値を表示する。

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
# 一番でかいやつと二番目のやつを見つける。
# 1番でかいやつが１つなら、基本最大値で、そいつがえらばれたら2番目の値教える。

max_val = max(A)
if len([i for i, x in enumerate(A) if x == max_val]) > 1:
    for i in range(0,N):
        print(max_val)
else:
    max_val_index = A.index(max_val)
    A[max_val_index] = 0
    sec_max_val = max(A)
    for i in range(0,N):
        if i == max_val_index:
            print(sec_max_val)
        else:
            print(max_val)
            
# 一番でかいやつが２つ以上いるなら、つねに1番の値を表示する。
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np

if __name__ == '__main__':
    A , B = map(int, input().split())

    num = 1
    tap = 0

    if B=1:
        print(0)
        exit()

    while True:
        tap += 1
        num -= 1
        num += A

        if num >=B:
            break

    print(tap)


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

if __name__ == '__main__':
    A , B = map(int, input().split())

    num = 1
    tap = 0

    if B==1:
        print(0)
        exit()

    while True:
        tap += 1
        num -= 1
        num += A

        if num >=B:
            break

    print(tap)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
import sys

sys.setrecursionlimit(20000)

def forward(matrix, plus, pos, counter):
    for i in range(pos+1,N):
        val = matrix[pos,i]
        if val == 1:
            counter[i] += plus
            save = pos
            forward(matrix, plus, i, counter)

if __name__ == '__main__':
    N, Q = map(int, input().split())

    matrix = np.zeros((N,N))
    counter = []
    for i in range(N):
        counter.append(0)

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

    P, X = [], []
    for i in range(Q):
        p, x = map(int, input().split())
        P.append(p-1)
        X.append(x)

    for p, x in zip(P,X):
        counter[p] += x
        forward(matrix, x, p, counter)

    out = str(counter[0])
    for i in range(len(counter)-1):
        out = out + ' ' + str(counter[i+1])

    print(out)


Fixed submission:
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    a = int(input())
    s = input()

    if a >= 3200:
        print(s)
    else:
        print('red')
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,N):
        A = math.gcd(a, T[i])
        a = a * T[i] // A

    print(a)


Fixed submission:
import fractions
N = int(input())
T = list(int(input()) for _ in range(N))
ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.gcd(ans, T[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,len(T)):
        A = int(math.gcd(int(a), int(T[i])))
        a = a * T[i] / A

    print(int(a))


Fixed submission:
import fractions
N = int(input())
T = list(int(input()) for _ in range(N))
ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.gcd(ans, T[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,len(T)):
        A = math.gcd(int(a), int(T[i]))
        a = a * T[i] / A

    print(int(a))


Fixed submission:
import fractions
N = int(input())
T = list(int(input()) for _ in range(N))
ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.gcd(ans, T[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

if __name__ == '__main__':
    N = int(input())
    T = []
    for i in range(N):
        T.append(int(input()))

    a = T[0]
    for i in range(1,len(T)-1):
        A = math.gcd(int(a), int(T[i]))
        a = a * T[i] / A

    print(int(a))


Fixed submission:
import fractions
N = int(input())
T = list(int(input()) for _ in range(N))
ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.gcd(ans, T[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

if __name__ == '__main__':
    N = int(input())
    val = len(N)
    li = []
    for i in range(1, math.ceil(math.sqrt(N))+1):
        if N % i == 0:
            a = len(str(int(i)))
            b = len(str(int(N/i)))
            print(a, b)
            c = max(a, b)

            if c < val:
                val = c

    print(val)



Fixed submission:
# -*- coding: utf-8 -*-
import math

if __name__ == '__main__':
    N = int(input())
    val = len(str(N))
    li = []
    for i in range(1, math.ceil(math.sqrt(N))+1):
        if N % i == 0:
            a = len(str(int(i)))
            b = len(str(int(N/i)))
            c = max(a, b)

            if c < val:
                val = c

    print(val)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
M=S.count('.')
ans=M

for i in range(N):
	if S[i] == '#':
		M = M+1
	else:
		M = M-1
    ans = min(M,ans)
print(ans)

Fixed submission:
N=int(input())
S=input()
M=S.count('.')
ans=M

for i in range(N):
	if S[i] == '#':
		M = M+1
	else:
		M = M-1
	ans = min(M,ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
result=3*(10**5)
for i in range(n-1):
	result=min(result,s[:i].count('W')+s[(i+1):].count('E'))
print(result)

Fixed submission:
n=int(input())
s=input()
a=b=s[1:].count('E')

for i in range(n-1):
	if s[i+1]=='E':
		b-=1
	if s[i]=='W':
		b+=1
	a=min(a,b)
print(a)
Buggy python submission (verdict: Runtime Error):
import math

x=int(input())

if x<4:
	print(x)
else:
	result=2
	for i in range(2,x):
		for j in range(2,x):
			if i**j<=x:
				result=max(result,i**j)
			else:
				break;
print(result)

Fixed submission:
import math

x=int(input())

if x<4:
	print(x)
else:
	result=2
	for i in range(2,x):
		for j in range(2,x):
			if i**j<=x:
				result=max(result,i**j)
			else:
				break
	print(result)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

result = 0
n,k = map(int,input().split())
input_list = input().split()
counter_list = collections.Counter(input_list)
if k < len(counter_list):
  for i in range(len(counter_list)-k):
    result += sorted(counter_list.values())[i]
print(result)

Fixed submission:
import collections

result = 0
n,k = map(int,input().split())
input_list = input().split()
counter_list = collections.Counter(input_list)
if k < len(counter_list):
  length = len(counter_list)-k
  sort_list = sorted(counter_list.values())
  for i in range(length):
    result += sort_list[i]
print(result)
Buggy python submission (verdict: Runtime Error):
n=int(input())
alist = [int(i) for i in input().split()]
ans=0
 
for i in range(n-1):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
if alist[n-1]=n:
	ans+=1
print(ans)

Fixed submission:
n=int(input())
alist = [int(i) for i in input().split()]
ans=0
 
for i in range(n-1):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
if alist[n-1]==n:
	ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
alist = [int(i) for i in input().split()]
ans=0

for i in range(n):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
print(ans)

Fixed submission:
n=int(input())
alist = [int(i) for i in input().split()]
ans=0
 
for i in range(n-1):
	if alist[i]==i+1:
		temp=alist[i+1]
		alist[i+1]=alist[i]
		alist[i]=temp
		ans+=1
if alist[n-1]==n:
	ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
P=list(map(int,input().split()))
ans=0
for i in range(2**N,2**(N+1)):
        B=bin(i)
        count=0
        for j in range(M):
            tet=0
            for l in range(A[j][0]):
                tet+=int(B[A[j][l+1]+2])
            if tet//2==P[j]:
                  count+=1
        if count==M:
            ans+=1
print(ans)
N,M=map(int,input().split())
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
P=list(map(int,input().split()))
ans=0
for i in range(2**N,2**(N+1)):
        B=bin(i)
        count=0
        for j in range(M):
            tet=0
            for l in range(A[j][0]):
                tet+=int(B[A[j][l+1]+2])
            if tet%2==P[j]:
                  count+=1
        if count==M:
            ans+=1
print(ans)


Fixed submission:
N,M=map(int,input().split())
A=[]
for i in range(M):
    A.append(list(map(int,input().split())))
P=list(map(int,input().split()))
ans=0
for i in range(2**N,2**(N+1)):
        B=bin(i)
        count=0
        for j in range(M):
            tet=0
            for l in range(A[j][0]):
                tet+=int(B[A[j][l+1]+2])
            if tet%2==P[j]:
                  count+=1
        if count==M:
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=0
B=0
A=0
count1=0
count2=0
for i in range(N):
    S=input()
    a+=S.count("AB")
    if S[0]=="B"and S[len(S)-1]=="A":
        a+=1
        count1+=1
    elif S[0]=="B":
        B+=1
        count2+=1
    elif S[0]=="A":
        A+=1
        count2+=1
if count1!=0:
    A+=1
    B+=1
if count2==0:
    a=a-1
C=min(A,B)
D=min(C,N-1)
print(a+D)

Fixed submission:
N=int(input())
count=0
for i in range(1,round(N**(1/2))):
    if N%i==0:
        count+=N//i-1
print(count)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
b=min(B)
c=min(C)
d=min(b,c)
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*c)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
        if C==[]:
            print(sum(B)+sum(C)-2*min(B))
        else:
            print(sum(B)+sum(C)-2*min(min(B),min(C)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
b=min(B)
c=min(C)
d=min(b,c)
if B==[]:
    print(sum(C))
elif len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*c)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
        if C==[]:
            print(sum(B)+sum(C)-2*min(B))
        else:
            print(sum(B)+sum(C)-2*min(min(B),min(C)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*min(min(B),min(C)))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
        if C==[]:
            print(sum(B)+sum(C)-2*min(B))
        else:
            print(sum(B)+sum(C)-2*min(min(B),min(C)))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*min(min(B),min(C))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
        if C==[]:
            print(sum(B)+sum(C)-2*min(B))
        else:
            print(sum(B)+sum(C)-2*min(min(B),min(C)))
Buggy python submission (verdict: Runtime Error):
A =int(input())
B=input()
c=int(input())
d=B[c]
E=""
for i in range(A):
    if B[i]==d:
        E=E+d
    else:
        E=E+"*"
print(E)

Fixed submission:
A =int(input())
B=input()
c=int(input())
d=B[c-1]
E=""
for i in range(A):
    if B[i]==d:
        E=E+d
    else:
        E=E+"*"
print(E)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[]
for i in range(5):
    A.append(int(input()))
B=[N,0,0,0,0,0]
j=0
while B[5]!=N:
        C=[]
        C.append(B[0]-min(B[0],A[0]))
        for i in range(4):
             C.append(B[i+1]+min(B[i],A[i])-min(B[i+1],A[i+1]))
        C.append(B[5]+min(B[4],A[4]))
        B=C
        j=j+1
print(j)

Fixed submission:
N=int(input())
A=[]
for i in range(5):
    A.append(int(input()))
a=min(A)
if N%a==0:
    print(5+N//a-1)
else:
    print(5+N//a)
Buggy python submission (verdict: Runtime Error):
T,X=map(int,input().split())
return T/X

Fixed submission:
T,X=map(int,input().split())
print(T/X)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=[]
for i in range(0,N):
    h.append(int(input()))
h_New=[]
for i in range(0,N):
    a=min(h)
    h_New.append(a)
    h.remove(a)
h_k=[]
for i in range(0,N-K+1):
    h_k.append(h_New[i+K-1]-h_New[i])
print(min(h_k))

Fixed submission:
def merge(a,b): #整列済みの配列aとbを併合
    r =[]
    #結果の格納先を用意
    ai = 0 #aは何番目まで処理したか?
    bi = 0 #bは何番目まで処理したか?
    for i in range(0, len(a)+len(b)):
        if (bi >= len(b) or (ai < len(a) and a[ai] < b[bi])):
         #aとbの先頭を比較(長さを超えないよう注意)
            r.append(a[ai])
            ai = ai + 1
        else:
            r.append(b[bi])
            bi = bi + 1 #aとbの先頭の小さい方をrへ
    return r
def mergesort(a): #配列aを整列
    n = len(a)
    if n <= 1: #短いときはそれでよし
        return a
    else:
        l = mergesort(a[0 : n//2])
        r = mergesort(a[n//2 : n])
        #前半と後半をそれぞれ整列
        return merge(l,r)
        #整列した結果を併合
N,K=map(int,input().split())
h=[]
for i in range(0,N):
    h.append(int(input()))
h_New=mergesort(h)
h_k=[]
for i in range(0,N-K+1):
    h_k.append(h_New[i+K-1]-h_New[i])
print(min(h_k))