peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())

d = defaultdict(int)
for i in range(n):
    s = input().rstrip()
    d[s] += 1

ma = 0
for v in d.values():
    ma = max(ma, v)

a = sorted(d.items())
for k, v in a:
    if ma == v:
        print(k)
# Judge status: Wrong Answer
import collections
n, k = map(int, input().split())
list = input().split()
c_list = collections.Counter(list)
sorted_c_list = sorted(c_list.values(),reverse=True)
print(sorted_c_list[k:])
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
#単数値での入力，桁ごとで分解する．
s = input()
a = [int(c) for c in s]
#出力値を設定
count = 0
#
for i in range(1, 3):
  if a[i] == 1:
  	count = count + 1
    
print(count)
# Judge status: Accepted
n,p=map(int,input().split())
a=list(map(lambda x:int(x)%2,input().split()))
if a.count(1)==0:
  print((1-p)*2**n)
else:
  print(2**(n-1))
# Judge status: Accepted
n = int(input())
print("ABC" if n <= 999 else"ABD")
# Judge status: Accepted
n = int(input())
Lists=list(map(int,input().split()))
x = 0
for i in Lists:
    if i%2==0 and i%3 !=0 and i%5!=0:
        print("DENIED")
        x = 1
        break

if x == 0:
    print("APPROVED")
# Judge status: Wrong Answer
H, N = map(int, input().split())
a = list(map(int, input().split()))

print(sum(a))

if H <= sum(a):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import sys
s=str(input()).replace("?", "@")
t=str(input())
cnt=0
ans=""
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if cnt==1:
      break;
      
    elif s[i+j]==t[j] and len(s)-i-j+1>len(t)-j:
      ans=s[:i]+t+s[i+len(t):]
      cnt+=1
if cnt>0:
  ans2=ans.replace("@", "a")
  print(ans2)
else:
  print("UNRESTORABLE")
# Judge status: Wrong Answer
N = int(input())

c1, c2, c4 = 0, 0, 0
a = list(map(int, input().split()))

for i in a:
    if i % 4 == 0:
        c4 += 1
    elif i % 2 == 0:
        c2 += 1
    else:
        c1 += 1

result = min(c4, c1*2) * 3 + c2 // 2

print("Yes" if result >= N else "No")
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))
memo = 0
for i in range(n-2):
  if((p[i]>p[i+1] and p[i+1]>p[i+2]) or (p[i]<p[i+1] and p[i+1]<p[i+2])):
    memo+=1
print(memo)
# Judge status: Accepted
X=int(input())
if X>=2000:
    print(1)
elif X//100*100<=X<=X//100*105:
    print(1)
else:
    print(0)
# Judge status: Accepted
# thought greedy was better i am noob
def main():
	n = int(input())
	dp = [0 for i in range(n+4)]
	dp[0]=0
	for i in range(1, n+2):
		p = 1
		dp[i]=1000000000000000
		while i>=p:
			dp[i]=min(dp[i] , dp[i-p]+1)
			p =p*9
		p=1
		while i>=p:
			dp[i]=min(dp[i] , dp[i-p]+1)
			p = p*6
	print(dp[n])
if __name__=="__main__":
	main()
# Judge status: Accepted
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys  # def input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(10**6)

s = input()
t = input()
ans = 0
for i in range(len(s)):
    if s[i] != t[i]:
        ans += 1

print(ans)
# Judge status: Wrong Answer
from collections import deque
n = int(input())
a = list(map(str,input().split()))
d = deque()

for i in range(len(a)):
    if i%2==0:
        d.append(a[i])
    else:
        d.appendleft(a[i])

for i in range(len(d)):
    print(d[i]+" ",end="")
# Judge status: Wrong Answer
N, A, B, C, D = map(int, input().split())
S = input()
if C < D:
    if '##' not in S[A:D - 1]:
        print('Yes')
    else:
        print('No')
else:
    if '...' in S[B - 2:D] and '##' not in S[A:C - 1]:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
import heapq

n, m = map(int, input().split())
memo = [[] for _ in range(m+1)]

for _ in range(n):
    a, b = map(int ,input().split())
    if a <= m:
        memo[a].append(-b)

ans = 0
HQ = []
heapq.heapify(HQ)
for i in range(1, m+1):
    for j in memo[i]:
        heapq.heappush(HQ, j)
    if HQ:
        ans += heapq.heappop(HQ)

print(-ans)
# Judge status: Wrong Answer
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
b = deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a.popleft())
    else:
        b.appendleft(a.popleft())

print(*b)
# Judge status: Accepted
N, K, S = map(int,input().split())
A = [S] * K
if N > K:
    if S < 10 ** 9:
        A.extend([S + 1] * (N - K))
    else:
        A.extend([S - 1] * (N - K))

print(A[0], end = "")
for i in range(1,N):
    print(" ", end = "")
    print(A[i], end = "")
# Judge status: Wrong Answer
N = int(input())
N_List = sorted(list(map(int,input().split())))
std = int(N/2)
ansstd = N_List[std] - N_List[std-1] 
print((0,ansstd)[ansstd > 1])
# Judge status: Accepted
# ABC 124: A – Buttons
a, b = [int(s) for s in input().split()]
print(max(a * 2 - 1, a + b, b * 2 -1))
# Judge status: Wrong Answer
N=int(input())

S=input()
LEN=len(S)
END='EEEEEEEEEEEEEEE'
S += END

R=S.count('R')
G=S.count('G')
B=S.count('B')


cnt=0
for j in range(1, int(LEN/2)):
    for i in range(LEN):
        if S[i+j+j]=='E':
            break
        if (S[i] != S[i+j]) and (S[i+j] != S[i+j+j]) and (S[i] != S[i+j+j]):
            cnt+=1

print(R*G*B-cnt)
# Judge status: Accepted
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

ans = 0

if m - n*2 >= 0:
    ans += n
    m -= n*2
    ans += m//4
    print(ans)
    exit()
else:
    if m % 2 == 0:
        print(m//2)
        exit()
    else:
        print((m-1)//2)
        exit()
# Judge status: Wrong Answer
a,b,c = map(int,input().split())
if c >= a + 2 * b:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
a,b = map(int,input().split())
n = input()
if 1<=a<=5 and 1<=b<=5:
  if n[a]=="-":
    if n[0:a].isdecimal() and n[a+1:a+b+1].isdecimal():
      print("Yes")
      exit()
print("No")
# Judge status: Accepted
a, b = map(int, input().split())

ans = a*b

print(ans)
# Judge status: Wrong Answer
k, x = map(int, input().split())

l = [x]
for i in range(1, k):
    l.append(x - i)
    l.append(x + i)
l.sort()
print(l)
# Judge status: Wrong Answer
n,m = map(int,input().split())

a = [[int(i) for i in input().split()] for _ in range(n)]
k=[]
ans = 0

for i in range(n):
  k.append(a[i][0])

for j in range(1,m+1):
  x = 0
  for i in range(n):
    
    for w in range(1,(k[i]+1)):
      if a[i][w] == j:
        x +=1
        print(a[i][w])
    if x ==n:
      ans +=1

print(ans)
# Judge status: Accepted
import sys

N=int(input())
W=[list(input()) for i in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if W[i]==W[j]:
            print("No")
            sys.exit()
for i in range(1,N):
    if W[i][0]==W[i-1][-1]:
        continue
    else:
        print("No")
        break
else:
    print("Yes")
# Judge status: Accepted
Q,H,S,D=list(map(int,input().split()))
N=int(input())
ans=(N//2)*min(8*Q,4*H,2*S,D)+(N%2)*min(4*Q,2*H,S)
print(ans)
# Judge status: Wrong Answer
N, = map(int, input().split())
X = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
ccs = []
for x in X:
    d[x] += 1
    if d[x] == 2:
        ccs.append(x)
ccs.sort()
if len(ccs) > 1:
    print(ccs[-1]*ccs[-2])
else:
    print(0)
# Judge status: Accepted
X,N = map(int,input().split())
P = set(list(map(int,input().split())))
if X not in P:
    print(X)
    exit()
i = 1
while 1:
    if X-i not in P:
        print(X-i)
        exit()
    if X+i not in P:
        print(X+i)
        exit()
    i += 1
# Judge status: Accepted
N, M = map(int, input().split())
c = [0] * N

for _ in range(M):
    a, b = map(int, input().split())
    c[a - 1] += 1
    c[b - 1] += 1

print(*c, sep='\n')
# Judge status: Accepted
S = str(input())
a=0
if 'R'in S:
    a=1
    if 'RR'in S:
        a=2
        if 'RRR'in S:
            a=3
print(a)
# Judge status: Wrong Answer

import itertools


def main():
    N = int(input())
    PArry = list(map(int, input().split()))
    QArry = list(map(int, input().split()))

    a = 0
    b = 0
    comb = [i for i in range(1, N+1)]
    for i, iter in enumerate(itertools.permutations(comb)):
        listIter = list(iter)
        if PArry == listIter:
            a = i+1
        if QArry == listIter:
            a = i+1

    print(abs(a-b))


if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(N):
    t[i+1], x[i+1], y[i+1] = map(int, input().split())
    
f = True
for i in range(N):
    dt = t[i+1] - t[i]
    dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
    if dt < dist:
        f = False
    if dist%2 != dt%2:
        f = False

if f:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
def solve(s, p=2019):
    s = s[::-1]
    memo = [0] * p
    memo[0] = 1
    ans = 0
    q = 0
    r = 1
    for c in s:
        q = (q + int(c)*r) % p
        ans += memo[q]
        r = 10*r % p
        memo[q] += 1
    return ans

s = input()
print(solve(s))
# Judge status: Accepted
from collections import defaultdict

N, M = map(int,input().split())
l = [tuple(map(int,input().split())) for i in range(M)]

# 3つめの要素でsort からの 2つめの要素でsort
l_sorted = sorted((y,p,i) for i,(p,y) in enumerate(l))

d = defaultdict(lambda: 0)

ans = [None] * M

for a,b,c in l_sorted:
    d[b] += 1
    ans[c] = str(b).zfill(6) + str(d[b]).zfill(6)
print(*ans, sep='\n')
# Judge status: Accepted
a,b=input().split()
ab=int(a+b)
rootab=ab**(1/2)//1
if(ab==rootab**2):
	print("Yes")
else:
	print("No")
# Judge status: Wrong Answer
N = int(input())
A = list(map(int ,input().split()))
MOD = 1e9+7

sum = 0
for i in range (N):
    sum += A[i]

ans = 0
for i in range(N):
    sum -= A[i]
    ans += (A[i] * sum) % MOD

ans = ans % MOD
print(ans)
# Judge status: Accepted
import bisect
N = int(input())
A = list(map(int, input().split()))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
check = [0] * N
ans = 0
for i in range(N):
    check[i] = N - bisect.bisect_right(C,B[i])
for i in range(1,N):
    check[N-1-i] += check[N-i]
for i in range(N):
    b = bisect.bisect_right(B,A[i])
    if b == N:
        continue
    ans += check[b]
print(ans)
# Judge status: Accepted
n,k = map(int,input().split())

ans = 0
mod = 10**9 + 7

for i in range(k,n+2):
    ans += i*(2*n - i + 1)//2 + 1
    ans %= mod
    ans -= i*(i-1)//2
    ans %= mod

print(ans)
# Judge status: Accepted
N = int(input())
H = list(map(int, input().split()))

cnt = 0
ans = 0
for i in range(N-1):
    if(H[i] >= H[i+1]):
        cnt += 1
    else:
        cnt = 0
    ans = max(ans, cnt)
print(ans)
# Judge status: Accepted
n,k=map(int,input().split())
h=sorted(list(map(int, input().split())))
res=0
if k>=n:res=0
else:
    res+=sum(h[:n-k])
print(res)
# Judge status: Accepted
a,b=map(int,input().split())
if a == b:
    print("Draw")
elif a == 1:
    print("Alice")
elif b == 1:
    print("Bob")
elif a > b:
    print("Alice")
elif a < b:
    print("Bob")
# Judge status: Accepted
N = int(input())
B = list(map(int, input().split()))

A = []

for i in range(len(B)):
    if i == 0:
        A.append(B[i])
    else:
        if B[i-1] < B[i]:
            A.append(B[i-1])
        else:
            A.append(B[i])
A.append(B[i])

ANS = 0

for i in range(len(A)):
    ANS = ANS + A[i]
print(ANS)
# Judge status: Accepted
n=int(input())

a=list(map(int,input().split()))

ans=0
max=a[0]
for i in range(1,n):
    if max>a[i]:
        ans+=max-a[i]
    else:
        max=a[i]

print(ans)
# Judge status: Accepted
N = int(input())
S = input()
diff = [0] * (N + 1)
for i in range(N):
    if S[i] == "(":
        diff[i + 1] = diff[i] + 1
    else:
        diff[i + 1] = diff[i] - 1
min_diff = min(diff)
print("(" * -min_diff + S + ")" * (diff[N] - min_diff))
# Judge status: Wrong Answer
N = int(input())
A_leaf = list(map(int, input().split()))
if N == 0:
    print(1 if A_leaf[0] == 1 else -1)
    exit()
s = [0]*(N+2)
for i in range(1, N+2):
    s[i] = s[i-1] + A_leaf[i-1]
node = [1]*(N+1)
for i in range(1, N+1):
    node[i] = min((node[i-1] - A_leaf[i-1])*2, s[N+1]-s[i])
    if node[i] <= 0:
        print(-1)
        exit()
else:
    print(sum(node))
# Judge status: Accepted
n = int(input())
X = []
Y = []
for i in range(n):
    x,y = map(int,input().split())
    X.append(x+y)
    Y.append(x-y)

print(max(max(X)-min(X),max(Y)-min(Y)))
# Judge status: Accepted
import collections
N,M = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(M)]
a.sort()
B = collections.Counter(x[0] for x in a)[1]
C = set([])
for i in range(B):
    C.add(a[i][1])
for i in range(M):
    if a[i][0] in C and a[i][1] == N:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
# Judge status: Wrong Answer
N = int(input())
S = input()

lst = []
for i in S:
    x = ord(i)
    if x + N > 90:
        x = x - 90 - 1 + 65
    lst.append(chr(int(x) + N))
print(lst)
# Judge status: Accepted
N=int(input())
if(N<1000):
    print("ABC")
else:
    print("ABD")
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
ans = 0
l = [0]*(3*10**5+10)
for i in range(1,N):
  x = i-A[i]
  if x<0:
    continue
  else:
    l[x]+=1
if A[0]<=2*10**5:
  ans+=l[A[0]]
for i in range(1,N):
  x = i+A[i]
  if x<0:
    continue
  if x>2*10**5:
    continue
  
  l[i-A[i]]-=1
  ans+=l[x]
  
print(ans)
# Judge status: Accepted
N,M=map(int, input().split())
l = []
for i in range(M):
  a,b=map(int, input().split())
  l.append(a)
  l.append(b)
for i in range(N):
  print(len([1 for x in l if x==i+1]))
# Judge status: Accepted
# CODE FESTIVAL 2017 予選 A: B – fLIP
N, M, K = [int(s) for s in input().split()]

canDo = 'No'

for n in range(0, N + 1):
    for m in range(0, M + 1):
        if n * (M - m) + m * (N - n) == K:
            canDo = 'Yes'
            break

print(canDo)
# Judge status: Wrong Answer
N=input()
if N[len(N)-1]=="2" or "4" or "5" or "7" or "9":
    print("hon")
elif N[len(N)-1]=="0" or "1" or "6" or "8":
    print("pon")
else:
    print("bon")
# Judge status: Wrong Answer
#!/usr/local/bin/python3
# coding: utf-8

import math
ha = input()
kita = ha.split(" ")
a = int(kita[0])
b = int(kita[1].replace(".",""))
m = a*b
m = str(m)
print(m[:-2])
# Judge status: Accepted
import math
n,k=map(int,input().split())
ans=0
cnt=0#2欠けた階数
for i in range(n):
    while(n-i<k):
        k=(k+1)//2
        cnt+=1
    ans+=1/(2**cnt)/n
print(ans)
# Judge status: Wrong Answer
import collections

def prime_factorize(n):
    a = []
    f = 2
    while n % f == 0:
        a.append(f)
        n //= f
        f *= 2 

    g = 3
    while g * g <= n:
        if n % g == 0:
            a.append(g)
            n //= g
            g += 2
        else:
            g += 2
    if n != 1 and n not in a:
        a.append(n)
    return a
N = int(input())
fact = prime_factorize(N)
print(len(fact))
# Judge status: Wrong Answer
n = int(input())
dic = {}

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

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = 0

for key in dic:
    if dic[key] > key:
        ans += dic[key] - key
    else:
        ans += dic[key]

print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
l = sum(A)
if l % N == 0:
  x = l // N
  s = 0
  for a in A:
    s += (a - x) ** 2
  print(s)
else:
  x = l // N
  y = x + 1
  s = 0
  t = 0
  for a in A:
    s += (a - x) ** 2
    t += (a - y) ** 2
  print(min(s, t))
# Judge status: Wrong Answer
S = input()
for i in range(len(S)):
    for j in range(i, len(S)):
        if "keyence" in S[:i] + S[j:]:
            print("YES")
            exit()

print("NO")
# Judge status: Accepted
k,s=map(int,input().split())
ans=0
for x in range(k+1):
    for y in range(k+1):
            if 0<=s-x-y<=k:ans+=1
print(ans)
# Judge status: Wrong Answer
import math
a=int(input())
print(math.floor(a)*math.ceil(a))
# Judge status: Wrong Answer
import bisect

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ct = 0

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_right(L, a+b)
        ct += max(0, up_bound - (j+1))

print(ct)
# Judge status: Accepted
import re
print(max([0]+[len(r) for r in re.findall("[ACGT]+",input())]))
# Judge status: Accepted
import sys
def S(): return sys.stdin.readline().rstrip()
S = S()
print(S[0:3])
# Judge status: Wrong Answer
a=int(input())
b=int(input())
if a%500 <b:
  print("No")
else:
  print("No")
# Judge status: Wrong Answer
N,K = map(int,input().split())
S = input()
ans = S
S = S[K-1].lower()
print(ans.replace(ans[K-1], S))
# Judge status: Accepted
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    d = defaultdict(list)
    for i in range(N):
        s, p = readline().strip().split()
        p = int(p)
        d[s].append((p, i+1))

    for city, points in sorted(d.items()):
        points = sorted(points, reverse=True)
        for _, i in points:
            print(i)

    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
a = [set() for _ in range(N)]

for i in range(N):
    id = int(input()) - 1
    a[id].add(i)

step = -1
#already = a[1]
now = a[1]
next = set()
for i in range(N-1):
    #already = already.union(now)
    if 0 in now:
        step = i+1
        break
    for j in now:
        next = next.union(a[j])
    now = next
    next = set()

print(step)
# Judge status: Accepted
#!/usr/bin/env python3
n, m = map(int, input().split())
if 2 * n > m:
    print(m // 2)
else:
    print(n + (m - 2 * n) // 4)
# Judge status: Wrong Answer


def main():
    a, b = map(int, input().split())
    cnt =  0
    for i in range(1, a+1):
        for j in range(1, b+1):
            if i == j:
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()
# Judge status: Accepted
n, x = map(int, input().split())
l = list(map(int, input().split()))
ans = 1
d = 0
for i in l:
    d = d + i
    if d <= x: ans += 1
print(ans)
# Judge status: Accepted
N = int(input())
H = list(map(int, input().split()))
H.reverse()

ans = True
for i in range(len(H) - 1):
    if H[i] + 1 == H[i + 1]:
        H[i + 1] -= 1
    if H[i] + 1 < H[i + 1]:
        ans = False
        break

if ans:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ans = [1] * n
check = [False] * n
check[0] = True
for i in range(m):
  x, y = map(int, input().split())
  if check[x - 1]:
    ans[y - 1] += 1
    ans[x - 1] -= 1
    check[y - 1] = True
    if ans[x - 1] == 0:
      check[x - 1] = False
print(check.count(True))
# Judge status: Accepted
t = input()
print(t.replace("?","D"))
# Judge status: Accepted
# ABC160 A

def main():
    s = input()

    if s[2] == s[3] and s[4] == s[5]:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n, m = map(int, input().split())

if n == 1 or m == 1:
    ans = max(n, m) - 2
else:
    ans = n * m - 2 * n - 2 * m + 4
    print(ans)

print(ans)
# Judge status: Accepted
import itertools
S = input().split()
m = 0
for n in itertools.permutations(range(3)):
    m = max(m, eval(S[n[0]]+"+"+S[n[1]]+S[n[2]]))
print(m)
# Judge status: Accepted
n, k = [int(x) for x in input().split()]
l = []
for i in range(k):
    d = input()
    l.extend(list(map(int, input().split())))
s = set(l)
print(n -len(s))
# Judge status: Accepted
N, M, K = map(int, input().split())
for i in range(N):
  for j in range(M):
    s = i * j + (N-i) * (M-j)
    if s == K or N*M - s == K:
      print("Yes")
      exit()
print("No")
# Judge status: Accepted
def solve():
    ans = 0
    N = int(input())
    for i in range(1,N+1):
        for j in range(1,N//i+1):
            ans += i*j
    return ans
print(solve())
# Judge status: Accepted
import collections

N, M = map(int, input().split())

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

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)

print("Yes")
print(*visited[1:], sep="\n")
# Judge status: Accepted
def resolve():
    n, k = map(int, input().split())
    H = []
    for _ in range(n):
        H.append(int(input()))
    H_sort = list(sorted(H, reverse=True))
    ans = 10**9
    for i in range(n-k+1):
        ans = min(ans, H_sort[i]-H_sort[i+k-1])
    print(ans)
resolve()
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N = int(input())


# In[12]:


ans = N
for i in range(N+1):
    x = 0
    y = i
    while y:
        x += y%6
        y //= 6
    y = N-i
    while y:
        x += y%9
        y //= 9
    ans = min(x, ans)
print(ans)


# In[ ]:
# Judge status: Accepted
from sys import stdin
import string

alpha = string.ascii_lowercase
nokori = [26-i for i in range(26)];nokori[0] = 0
s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())
sin = ""
for i in s:
    if nokori[alpha.index(i)] <= k:
        k -= nokori[alpha.index(i)]
        sin += "a"
    else:
        sin += i
q = alpha.index(sin[-1])
q += k
print(sin[:-1]+alpha[q%26])
# Judge status: Accepted
n = int(input())
num = 0

for i in range(1,n):
    num += (n-1)//i

print(num)
# Judge status: Accepted
def main():
    A, B, K = map(int, input().split())
    if K < A:
        print(A - K, B)
    elif K < A + B :
        print(0, B - (K - A))
    else:
        print(0, 0)


if __name__ == '__main__':
    main()
# Judge status: Accepted
X = int(input())
if(X >= 30):
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
n=int(input())
a=[0]*(n+1)
six=0
nine=0
for i in range(1,n+1):
  if i>6**(six+1):
    six+=1
  if i>9**(nine+1):
    nine+=1
  a[i]=min(a[i-1],a[i-6**six],a[i-9**nine])+1
print(a[n])
# Judge status: Accepted
N = int(input())
P = list(map(int, input().split()))

count = 1
mini = P[0]
for i in range(1, N):
    mini = min(mini, P[i])
    if P[i] <= mini:
        count += 1

print(count)
# Judge status: Accepted
a,b = map(int,input().split())
s=input()
for i in range(len(s)):
  if i+1==b:
    print(s[i].lower(),end='')
    continue
  print(s[i],end='')
# Judge status: Wrong Answer
A, B = map(int, input().split())

print(A+B)
# Judge status: Accepted
N = int(input())
l = []
for i in range(N):
  l.append(int(input()))
  
ans = 0
for i in range(N):
  ans += l[i] // 2
  l[i] = l[i] % 2
  if (i<N-1) and (l[i]==1) and (l[i+1]>0):
    ans += 1
    l[i] = 0
    l[i+1] -= 1
print(ans)
# Judge status: Accepted
n,m = map(int,input().split())
a = set([int(input()) for i 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])
# Judge status: Accepted
n = int(input())
from math import sqrt
root = int(sqrt(n))

for i in range(root,0,-1):
    if n%i == 0:
        ans = i+(n/i)-2
        break
print(int(ans))
# Judge status: Accepted
N = list(map(int,list(input())))
if sum(N) % 9 == 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
a, b, c = map(int, input().split())

if a >= c >= b or a <= c <= b:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = int(input())
cnt = 0
for a in range(n):
    for b in range(n):
        for c in range(n):
            if a * b + c == n:
                cnt += 1
print(cnt)
# Judge status: Wrong Answer
s, t = map(str, input().split())
a, b = map(int, input().split())
n = input()
if n == a: print(a-1, b)
else: print(a, b-1)