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

Fixed submission:
a, b = map(int, input().split())
print("{:.10f}".format(a/b))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
X = sorted(map(int,input().split()))
l = sorted([X[i+1] - X[i] for i in range(m-1)])
print(sum(l[:-n+1]))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print({:.10f}.format(a/b))
Problem p03834 (python)

Fixed submission:
a,b,c = input().split(",")
print(a+" "+b+" "+c)

Buggy submission (verdict: Runtime Error):
a,b,c = input().split(,)
print(a+" "+b+" "+c)
Problem p03327 (python)

Fixed submission:
def main():
    num = int(input())
    if num<1000:
        ans = 'ABC'
    elif num < 1999:
        ans = 'ABD'
    else:
        print("error")
        
    print(ans)
    
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def summation(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return n + summation(n-1)


def main():
    a,b = map(int, input().split())
    
    n_plus1 = b-a
    
    ans = summation(n_plus1) - b
    
    print(ans)

    
if __name__ == "__main__":
    main()
Problem p03329 (python)

Fixed submission:
# ある数Nのみで割っていく関数
def div_by_N(inpt, N):
    if inpt < N:
        return inpt
    else:
        ans = 0
        while inpt>0:
            ans += inpt%N
            inpt = inpt // N
        return ans
        
def main():
    inpt = int(input())
    ans = 1000000
    for i in range(inpt+1):
        ans = min(ans, div_by_N(i,6)+div_by_N(inpt-i,9))
    print(ans)
    
    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    
    N = int(input())
    
    POW6 = []
    POW9 = []
    for i in range(7):
        POW6.append(6**i)
        
    for i in range(6):
        POW9.append(9**i)
        
    
    dp = [N]*(N+1)
    dp[0] = 0
    for i in range(1, N+1):
        cnt = 0
        while i-POW6[cnt] >= 0:
            dp[i] = min(dp[i], dp[i-POW6[cnt]]+1)
            cnt += 1
        cnt = 0
        while i-POW9[cnt] >= 0:
            dp[i] = min(dp[i], dp[i-POW9[cnt]]+1)
            cnt += 1

    
    print(dp[N])
    
    
if __name__ == "__main__":
    main()
Problem p03464 (python)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def judge(k:int, a:list):
    mi = ma = 2
    for ai in a[::-1]:
        # miをaiの倍数に切り上げる
        if mi%ai:
            mi += ai - mi%ai
            
        ma += (ai - 1) - (ma % ai)
        
        if ma < mi:
            return False, (-1,-1)
        
    return True, (mi,ma)

k = ni()
a = list(li())

tf, (mi,ma) = judge(k,a)
if tf:
    print(mi,ma)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**6) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

k = ni()
a = list(li())

exist = True

# lower
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        exist = False
        for yi in range(lower, upper+1):
            if yi % ai == 0:
                lower = yi
                upper = lower+ai-1
                exist = True
                break
            
        if not exist:
            break
                
                
                
ans_lower = lower


# upper
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        exist = False
        for yi in range(upper, lower-1, -1):
            if yi % ai == 0:
                lower = yi
                upper = lower+ai-1
                exist = True
                break
            
        if not exist:
            break
                
    
ans_upper = upper

        
print(ans_lower, ans_upper) if exist else print(-1)
Problem p03822 (python)

Fixed submission:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def dfs(v: int, graph: list) -> int:
    if graph[v] == []:
        return 0
    
    else:
        ret = -1
        cands = []
        for ch in graph[v]:
            cands.append(dfs(ch, graph))
            
        cands.sort(reverse=True)
        
        for idx, cand in enumerate(cands):
            ret = max(ret, idx+1 + cand)
            
        return ret
    

n = ni()
graph = [[] for _ in range(n)]

person = 1
for _ in range(n-1):
    ai = ni()-1
    graph[ai].append(person)
    
    person += 1
    
ans = dfs(0, graph)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

def rec(n, memo):
    if memo[n] != -1:
        return memo[n]
    
    if len(graph[n]) == 0:
        memo[n] = 0
        return 0
    
    else:
        cnt = Counter()
        for child in graph[n]:
            cnt[rec(child, memo)] += 1
            
        memo[n] = max(cnt.keys())+1 + (sum(cnt.values()) - len(cnt))
        return memo[n]

n = ni()
memo = [-1]*n
graph = [[] for _ in range(n)]
i = 1
for _ in range(n-1):
    ai = ni() - 1
    graph[ai].append(i)
    i += 1
    
print(rec(0, memo))
Problem p03041 (python)

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

s[k-1] = s[k-1].swapcase()
print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
s = [int(i+j) for (i,j) in zip(s[::2],s[1::2])]

zero = int('{0:02d}'.format(0))

if zero <= s[0] <= 12:
  if zero <= s[1] <= 12:
    print("AMIGUOUS")
  else:
    print("MMYY")
else:
  if zero <= s[1] <= 12:
    print("YYMM")
  else:
    print("NA")

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

print(join(s[k-1].swapcase()))

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

print(s[k-1].swapcase)
Problem p03315 (python)

Fixed submission:
s = list(input())
a = s.count("+")
b = s.count("-")
print(a - b)

Buggy submission (verdict: Runtime Error):
s = list(map(str, input()))
a = s.count(+)
b = s.count(-)
print(a - b)

Buggy submission (verdict: Runtime Error):
s = map(int, input().split(1))
a = s.count(+)
b = s.count(-)
print(a - b)
Problem p02627 (python)

Fixed submission:
ch = input()
if ch == 'a' or ch == 'b' or ch == 'c' or ch == 'd' or ch == 'e' or ch == 'f' or ch == 'g' or ch == 'h':
  print('a')
elif ch == 'i' or ch == 'j' or ch == 'k' or ch == 'l' or ch == 'm' or ch == 'n' or ch == 'o':
  print('a')
elif ch == 'p' or ch == 'q' or ch == 'r' or ch == 's' or ch == 't' or ch == 'u' or ch == 'v':
  print('a')
elif ch == 'w' or ch == 'x' or ch == 'y' or ch == 'z':
  print('a')
else:
 print('A')

Buggy submission (verdict: Runtime Error):
a = input()
if a.islower():
  ptint('a')
else:
  print('A')

Buggy submission (verdict: Runtime Error):
ch = input()
if ch == a or ch == b or ch == c or ch == d or ch == e or ch == f or ch == g or ch == h:
  print(a)
elif ch == i or ch == j or ch == k or ch == l or ch == m or ch == n or ch == o:
  print(a)
elif ch == p or ch == q or ch == r or ch == s or ch == t or ch == u or ch == v:
  print(a)
elif ch == w or ch == x or ch == y or ch == z:
  print(a)
else
 print(b)
Problem p02627 (python)

Fixed submission:
a = input()
if a.isupper():
  print("A")
else:
  print("a")

Buggy submission (verdict: Runtime Error):
a = str(input())
if a.isupper():
  print("A")
else:
  peint("a")

Buggy submission (verdict: Runtime Error):
a = input()
if a.isupper():
  print("A")
else:
  peint("a")

Buggy submission (verdict: Runtime Error):
a = input()
if a == a.upper():
  print(a)
else:
  peint(a.lower())
Problem p02754 (python)

Fixed submission:
N, A, B = map(int, input().split())
kaisu = N//(A+B)

n = N-((A+B)*kaisu)
if n >= A:
    print(A*(kaisu+1))
else:
    print(A*kaisu+n)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
ball = []
kaisu = -(-N//(A+B))

for n in range(kaisu):
    ball += [0]*A
    ball += [1]*B

ball = ball[:N]
print(ball.count(0))
Problem p02831 (python)

Fixed submission:
from fractions import gcd
A, B = map(int,input().split())
n = (A * B) // gcd(A, B)
print(n)

Buggy submission (verdict: Runtime Error):
from math import gcd
A, B = map(int,input().split())
n = (A * B) // gcd(A, B)
print(n)
Problem p02916 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if (cnt > 0) and (a[i]==(a[i-1]+1)):
        cnt += c[a[i-1]-1]

    cnt += b[a[i]-1]
    
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if (cnt > 0) and (a[i]==(a[i-1]+1)):
        cnt += c[i]

    cnt += b[a[i]-1]
    
print(cnt)
Problem p02935 (python)

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

v.sort()

for i in range(len(v)):
    if i==0:
        continue

    a = v.pop(1)
    b = v.pop(0)
    v.insert(0, (a+b)/2)


print(v[0])

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

v.sort()

for i in range(len(v)):
    if i==0:
        continue
    v.append((v[i-1]+v[i])/2)
    v.pop(i)
    v.pop(i-1)


print(v[0])
Problem p02793 (python)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
b = []
b_sum = 0
mod = 10**9+7
for i in range(n):
    b_sum += (ans // a[i])

print(b_sum % mod)

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
mod = 10**9 + 7
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
b = []
for i in range(n):
    an = ans / a[i]
    b.append(an)

m = sum(b) % mod
print(int(m))

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
mod = 10**9 + 7
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
b = []
for i in range(n):
    an = ans / a[i]
    b.append(an)

print(int(sum(b) % mod))

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
b = []
for i in range(n):
    an = ans / a[i]
    b.append(int(an))
m = sum(b) % 10**9+7
print(m % (10**9  + 7))
Problem p02831 (python)

Fixed submission:
import fractions
a,b = map(int,input().split())
ans = (a * b) // fractions.gcd(a,b)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int,input().split())
ans = (a * b) // math.gcd(a,b)
print(ans)
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = set([int(input()) for _ in range(M)])
mod = 1000000007
dp = [0] * (n+1)
dp[0] = 1#0段目へ行く移動方法は1通りしかない
if 1 not in a:#もし階段がぶっ壊れてるリストに1段目が入っていないならば1段目へ行く移動方法は1通り、そうでないなら0通り
    dp[1] = 1
else:
    dp[1] = 0
for i in range(2,n+1):#2段目から調べていく
    if i in a:#現在のi段目がぶっ壊れリストに含まれてるなら何もせず飛ばす
        continue
    dp[i] = dp[i-1] + dp[i-2]#フィボナッチで処理
    dp[i] %= mod#modで割っていく
print(dp[n])#n+1番目を出力する

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
cnt = 0
lists = []
kaidan = list(range(N+1))
ans = []
for i in range(M):
    a = int(input())
    lists.append(a)

def dfs(i):
    if i == N:
        return cnt + 1
    
    if i > N:
        return False

    if i in lists:
        return False
    
    if dfs(i+1):
        return dfs(i+1)
    
    if dfs(i+2):
        return dfs(i+2)

    return False

m = dfs(0)
print(m+m)
Problem p03774 (python)

Fixed submission:
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = 9999999999999999999999999
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            ind = j
    lists.append(ind+1)
for i in range(len(lists)):
    print(lists[i])

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = abs(a_list[0] - c_list[0]) + abs(b_list[0] - d_list[0])
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            index = j
    lists.append(index+1)
for i in range(len(lists)):
    print(lists[i])

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
max = 0
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = 9999
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            index = j
    lists.append(index+1)
for i in range(len(lists)):
    print(lists[i])
Problem p03805 (python)

Fixed submission:
N, M = map(int, input().split())

path_matrix = []

#無向行列の初期化
for n in range(N):
    path_matrix.append([False] * N)

#まず無向グラフを表す行列を作る
for m in range(M):
    a,b = map(int, input().split())
    path_matrix[a-1][b-1] = True
    path_matrix[b-1][a-1] = True
#無向グラフを表す行列はpath_matrix[i][j]iの部分が各頂点でjが他の頂点との繋がりを意味する
#最初はvisited、つまり訪問したことのあるノードはひとつもないので、Falseにする
visited = [False] * N #この問題は各頂点をすべて通る方法を調べること
def dfs(now,depth):
    if visited[now]:#もし現在位置が訪問済みなら
        return 0
    if depth == N-1:#もし深さが最大までいったらすべての頂点を探索し終えたので１を返す
        return 1
    
    visited[now] = True#現在位置を訪問済みにする(これをしないとループし続ける)
    total_path = 0
    for i in range(N):
        if path_matrix[now][i]:#もし飛べる先があるのなら、その飛んだ先のノードで今いる位置と深さを更新した上で、もっと掘り下げてみる
            total_path += dfs(i,depth+1)#もし深さが最大まで行ったらすべての頂点について探索が終了したので1加える

    visited[now] = False

    return total_path


print(dfs(0,0))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
q = []
for i in range(m):
    a, b = map(int, input().split())
    q.append({a, b})
cnt = 0
array = list(range(1, m+1))
while cnt != 10000:
    a = q.pop()
    for j in q:
        if len(j & a) != 0:  # jとaに共通の値があるならば
            j |= a
            count = 0
            break
        else:  # jとaに共通の値がなければ
            q = [a] + q
    if count > len(q):
        break
    count += 1
    for i in q:
        tmp = list(i)
        if tmp == array:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
q = []
for i in range(m):
    a, b = map(int, input().split())
    q.append({a, b})
cnt = 0
array = list(range(1, n+1))
while cnt != 10000:
    a = q.pop()
    for j in q:
        if len(j & a) != 0:  # jとaに共通の値があるならば
            j |= a
            count = 0
            break
        else:  # jとaに共通の値がなければ
            q = [a] + q
    if count > len(q):
        break
    count += 1
    for i in q:
        tmp = list(i)
        if tmp == array:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
q = []
for i in range(m):
    a, b = map(int, input().split())
    q.append({a, b})
cnt = 0
while cnt != 10000:
    a = q.pop()
    for j in q:
        if len(j & a) != 0:  # jとaに共通の値があるならば
            j |= a
            count = 0
            break
        else:  # jとaに共通の値がなければ
            q = [a] + q
    if count > len(q):
        break
    count += 1
    for i in q:
        tmp = list(i)
        if tmp == array:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
import itertools
n, m = map(int, input().split())
array = list(range(1, n + 1))
p = list(itertools.permutations(array))
q = []
for i in range(m):
    a, b = map(int, input().split())
    q.append({a, b})
cnt = 0
while cnt != 10000:
    a = q.pop()
    for j in q:
        if len(j & a) != 0:  # jとaに共通の値があるならば
            j |= a
            count = 0
            break
        else:  # jとaに共通の値がなければ
            q = [a] + q
    if count > len(q):
        break
    count += 1
    for i in q:
        tmp = list(i)
        if tmp == array:
            cnt += 1
print(cnt)
Problem p02793 (python)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

aset = set(a)

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

if n == 1:
    print(1)

elif 1 < n:
    g = lcm(a[0], a[1])

    if n != 2:
        for val in aset:
            g = lcm(g, val)

    ans = 0
    for val in a:
        ans += g//val

    print(ans % mod)

Buggy submission (verdict: Runtime Error):
import fractions

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

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

g = lcm(a[0], a[1])

for val in a[2:]:
    g = lcm(g, val)

ans = 0
for val in a:
    ans += g//val % mod

print(ans % mod)
Problem p03038 (python)

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

changer = []
for i in range(m):
    p, c = map(int, input().split())
    changer.append((p, c))

changer.sort(key=lambda x: x[1])

cur = 0
while len(changer) and cur < n:
    p, c = changer.pop()
    i = cur
    while i < n and i < cur + p:
        if cards[i] < c: cards[i] = c
        else: break
        i += 1
    cur = i
print(sum(cards))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
cards = sorted(list(map(int, input().split())))
sum_cards = [cards[0]]
for i in range(1, n):
    sum_cards.append(cards[i-1] + cards[i])

changer = []
for i in range(m):
    p, c = map(int, input().split())
    gap = p*c - sum_cards[p-1]
    changer.append((p, c, gap))

changer.sort(key=lambda x: x[2])

cur = 0
while len(changer):
    p, c, _ = changer.pop()
    i = cur
    while i < cur + p:
        if cards[i] < c: cards[i] = c
        else: break
        i += 1
    cur = i
print(sum(cards))
Problem p03077 (python)

Fixed submission:
import math

n = int(input())
traffic_list = [int(input()) for _ in range(5)]

print(4 + math.ceil(n/min(traffic_list)))

Buggy submission (verdict: Runtime Error):
n = int(input())
*args, = [int(input()) for _ in range(n)]

worst = min(args)

print(6 + n // worst)
Problem p03107 (python)

Fixed submission:
s = input()
zero = s.count('0')
one = s.count('1')

print(min(zero, one) * 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
input_list = list(map(int, input().split()))
ans_list = input_list[::-2] + input_list[n%2::2]
print(*ans_list)
Problem p03137 (python)

Fixed submission:
def func2(input_list):
    if n >= m:
        return 0

    input_list.sort()

    input_diff = []
    for i in range(m-1):
        diff = input_list[i+1] - input_list[i]
        input_diff.append(abs(diff))

    input_diff.sort(reverse=True)
    ans = input_list[-1] - input_list[0]
    for i in range(0, n-1):
        ans -= input_diff[i]

    return ans

n, m = map(int, input().split())
input_list = [int(i) for i in input().split()]

print(func2(input_list))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

cnt = 0
while c > 0:
    c -= 1
    cnt += 1
    if b > 0:
        b -= 1
        cnt += 1
        continue
    elif a > 0:
        a -= 1
        continue
    else:
        break

print(cnt)
Problem p03208 (python)

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

input_list = []
for i in range(n):
    input_list.append(int(input()))

input_list.sort()

ans = float('inf')
ans_index = 0
for i in range(n-k+1):
    h = input_list[i+k-1] - input_list[i]
    ans = min(ans, h)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
sentences = [[] for i in range(n)]

for i in range(n):
    nn = int(input())

    for j in range(nn):
        p, t = map(int, input().split())
        sentences[i].append([p - 1, t])

ans = 0
count = 0
for i in range(2 ** n):
    check = {}
    success = True
    for j in range(n):
        # print('i, j:', i, j, bin(i))
        if ((i >> j) & 1):
            sentence = sentences[j]

            for pp, tt in sentence:
                if pp in check:
                    if check[pp] == tt:
                        pass                         
                    else:
                        success = False
                        break
                else:
                    check[pp] = tt
            #print(check)
        else:
            sentence = sentences[j]

            for pp, tt in sentence:
                if pp in check:
                    if check[pp] != tt:
                        pass                         
                    else:
                        success = False
                        break
                else:
                    if tt == 1:
                        check[pp] = 0
                    else:
                        check[pp] = 1

        if success == False:
            # print('break')
            break

    if success:
        # print(check)
        count = bin(i).count('1')    
        ans = max(ans, count)

    # print('c, a:', count, ans)

print(ans)