Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

d = {}
for ai in a:
    if ai not in d.keys():
        d[ai] = 1
    else:
        d[ai] += 1

ans = 0
for k, v in d.items():
    if k > v:
        ans += v
    else:
        ans += v - k

print(ans)

### FIXED CODE ###

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

x = a[0]
cnt = 0
ans = 0
for i in range(n):
    if x == a[i]:
       cnt += 1
    else:
        if cnt < x:
            ans += cnt
        else:
            ans += cnt - x
        x = a[i]
        cnt = 1

if cnt < x:
    ans += cnt
else:
    ans += cnt - x

print(ans)
### BUGGY CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j < wv[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-wv[i][0]] + wv[i][1])
print(dp[N][W])

### FIXED CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j < wv[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-wv[i][0]] + wv[i][1])
print(dp[N][W])
### BUGGY CODE ###

n = int(input())
x = n
while x * x > n :
    x = x - 1
    
print(x*x)

### FIXED CODE ###

n = int(input())
import math as m
x = round(m.sqrt(n)) + 1
while x > m.sqrt(n) :
    x = x - 1
    
print(x*x)
### BUGGY CODE ###

import math
a,b,x=map(int,input().split())
for i in range(a,b+1):
    if i%x==0:
        print((b//x)-math.ceil(a/x)+1)
        exit()

print(0)


### FIXED CODE ###

import math
a,b,x=map(int,input().split())
if a%x>0 and b//x-a//x==0:
    print(0)
else:
    print((b//x)-math.ceil(a/x)+1)
### BUGGY CODE ###

N=int(input())
E=[[] for _ in range(N)]
for _ in range(N-1):
    A,B=map(int,input().split())
    E[A-1].append(B-1)
    E[B-1].append(A-1)
MOD=10**9+7

#頂点xから伸びる部分木に含まれる頂点の個数のリストを返す
def get_sub_tree_node_nums(x):
    ret=[]
    used=[False]*N
    used[x]=True
    for s in E[x]:
        n=1
        stack=[s]
        used[s]=True
        while stack:
            node=stack.pop()
            for ss in E[node]:
                if not used[ss]:
                    stack.append(ss)
                    n+=1
                    used[ss]=True
        ret.append(n)
    return ret

n2=[0]*(N+1)
inv2=[0]*(N+1)
def calc_inv2():
    n2[0]=inv2[0]=1
    for i in range(1,len(inv2)):
        n2[i]=n2[i-1]*2%MOD
        inv2[i]=pow(1<<i,MOD-2,MOD)

def solve():
    ans=0
    for i in range(N):
        p=0
        subnodes = get_sub_tree_node_nums(i)
        if len(subnodes)>=2:
            #p0=すべての部分木に黒頂点が1つも含まれない確率
            p0=inv2[N-1]
            #p0*(p1-1)=どれか1つの各部分木に黒頂点が1つ以上含まれる確率
            p1=1
            for s in subnodes:
                p1+=n2[s]-1
                p1%=MOD
            p=1-(p0*p1)
            p%=MOD
            #頂点iが白の確率
            p=p*inv2[1]%MOD
        ans+=p
        ans%=MOD
    print(ans)
            
calc_inv2()
solve()

### FIXED CODE ###

N=int(input())
E=[[] for _ in range(N)]
for _ in range(N-1):
    A,B=map(int,input().split())
    E[A-1].append(B-1)
    E[B-1].append(A-1)
MOD=10**9+7

#dp=子ノードの数+1(自分)
dp=[1]*N

root=0
parent=[0]*N
order=[]
def dfs():
    parent[root]=root
    stack=[root]
    while stack:
        node=stack.pop()
        order.append(node)
        for ss in E[node]:
            if parent[node]!=ss:
                stack.append(ss)
                parent[ss]=node

pow2=[1]*(N+1)
for i in range(1,len(pow2)):
    pow2[i]=pow2[i-1]*2%MOD

def solve():
    ans=0
    inv2=pow(2,MOD-2,MOD)
    #p0=すべての部分木に黒頂点が1つも含まれない確率
    p0=pow(pow2[N-1],MOD-2,MOD)
    for i in reversed(order):
        if root!=i:
            dp[parent[i]]+=dp[i]
        p=0
        if len(E[i])>=2:
            #p0*(p1-1)=どれか1つの各部分木に黒頂点が1つ以上含まれる確率
            p1=1
            for s in E[i]:
                size=0
                if parent[i]!=s:
                    size=dp[s]
                elif i!=root:
                    size=N-dp[i]
                else:
                    continue
                p1+=pow2[size]-1
            p=1-(p0*p1)
            p%=MOD
        ans+=p
        ans%=MOD
    #頂点iが白の確率
    ans=ans*inv2%MOD
    print(ans)

dfs()
solve()
### BUGGY CODE ###

import numpy as np
from numba import njit, i8, u1, void, b1
import heapq
import math

@njit(i8(i8,i8,i8,i8,b1[:,:]),cache=True)
def solve(ch,cw,dh,dw,road_map):

    h,w = road_map.shape
    queue = [(0,ch*w+cw)]
    max_l = 2<<30
    used_map = np.full(h*w,max_l,dtype=np.int64)
    goal = dh*w+dw

    #move walk
            
    while len(queue) != 0:
        tl,n = heapq.heappop(queue)
        th,tw = divmod(n,w)
        used_map[n] = tl
        if n == goal:
            break

        for x in range(-2,3,1):
            for y in range(-2,3,1):
                if x == y == 0:
                    continue
                if abs(x)+abs(y) <= 1:
                    loop = tl
                else:
                    loop = tl+1
                tx = th + x
                ty = tw + y
                next_n  = tx*w+ty
                if tx < 0 or ty < 0 or tx >= h or ty >= w or road_map[tx][ty] == True:
                    continue
                check = used_map[next_n]
                if check > loop:
                    heapq.heappush(queue,(loop,next_n))

    if used_map[goal] == max_l:
        return -1
    else:
        return used_map[goal]

h,w = map(int,input().split())
ch,cw = map(int,input().split())
ch,cw = ch-1,cw-1
dh,dw = map(int,input().split())
dh,dw = dh-1,dw-1
road_map = np.array([[c=="#" for c in input()] for _ in range(h)])

print(solve(ch,cw,dh,dw,road_map))



### FIXED CODE ###

#shotoyooさんのコードをお借りしてテスト

import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp

@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
    inf = 1<<30
    h,w = ss.shape
    start = ch*w+cw
    goal = dh*w+dw
    n = h*w
    seen = np.full(n, inf, np.int64)
    seen[start] = 0
    q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
    while q:
        pnum,pu = hpp(q)
        ux,uy = divmod(pu,w)
        if pu==goal:
            break
        for xx in range(-2, 3):
            for yy in range(-2, 3):
                if xx==yy==0:
                    continue
                if abs(xx)+abs(yy)<=1:
                    vv = 0
                else:
                    vv = 1
                x,y = ux+xx, uy+yy
                u = x*w + y
                num = pnum+vv
                if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
                    continue
        #         print(x,y)
                if seen[u]>num:
                    seen[u] = num
                    hp(q,(num, u))
                
    val = seen[goal]
    if val==inf:
        return -1
    else:
        return val
      

h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
ss = np.array([[c=="#" for c in input()] for _ in range(h)])

print(main(ss,ch,cw,dh,dw))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right

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

neg = bisect_left(A, 0)
pos = bisect_right(A, 0)

def less(x):
    res = 0
    b = 0
    for i in range(0, neg):
        while b != N and A[i] * A[b] >= x:
            b += 1
        while b != 0 and A[i] * A[b - 1] < x:
            b -= 1
        res += max(i - b, 0)
    for i in range(neg, pos):
        if x > 0:
            res += i
    for i in range(pos, N):
        while b != N and A[i] * A[b] < x:
            b += 1
        while b != 0 and A[i] * A[b - 1] >= x:
            b -= 1
        res += min(b, i)
    return res

l = - (10 ** 18 + 1)
r = - l
while l + 1 < r:
    m = (l + r) // 2
    if less(m) < K:
        l = m
    else:
        r = m
print(l)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right

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

neg = bisect_left(A, 0)
pos = bisect_right(A, 0)

def less(x):
    res = 0
    b = 0
    for i in range(0, neg):
        while b != N and A[i] * A[b] >= x:
            b += 1
        while b != 0 and A[i] * A[b - 1] < x:
            b -= 1
        res += max(i - b, 0)
    for i in range(neg, pos):
        if x > 0:
            res += i
    for i in range(pos, N):
        while b != N and A[i] * A[b] < x:
            b += 1
        while b != 0 and A[i] * A[b - 1] >= x:
            b -= 1
        res += min(b, i)
    return res

l = - (10 ** 18 + 1)
r = - l
while l + 1 < r:
    m = (l + r) // 2
    if less(m) < K:
        l = m
    else:
        r = m
print(l)
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
# A_dic = {A[i]: i for i in range(N)} #value: idx
A_items = [[A[i], i] for i in range(N)]
A_items = sorted(A_items, reverse=True)
# その時の最大のAに１つ使う　これを繰り返す
ans = [0]*N # iに使うチケットの枚数
total = 0
rest = M
if N == 1:
    while rest > 0:
        rest -= 1
        A[0] //= 2
    total = A[0]
elif N == 2:
    while rest > 0:
        rest -= 1
        if A[0] >= A[1]:
            A[0] //= 2
        else:
            A[1] //= 2
    total = A[0] + A[1]
else:
    while rest > 0:
        temp_idx = A_items[0][1]
        while A_items[0][0] >= A_items[1][0]:
            ans[temp_idx] += 1
            rest -= 1
            A_items[0][0] //= 2
            A[temp_idx] //= 2
        
        idx = 2
        while A_items[0][0] < A_items[idx][0]:
            idx += 1
            if idx >= N-1:
                break
        u, v = A_items[0], A_items[idx-1]
        A_items[idx-1] = u
        A_items[0] = v
    total = sum(A)

print(total)

### FIXED CODE ###

import sys
input = sys.stdin.readline
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
A_dic = {} #value: idx
for i in range(N):
    if A[i] not in A_dic:
        A_dic[A[i]] = []
    A_dic[A[i]].append(i)

# その時の最大のAに１つ使う　これを繰り返す
total = 0
rest = M
if N == 1:
    while rest > 0:
        rest -= 1
        A[0] //= 2
    total = A[0]
elif N == 2:
    while rest > 0:
        rest -= 1
        if A[0] >= A[1]:
            A[0] //= 2
        else:
            A[1] //= 2
    total = A[0] + A[1]
else:
    hq = [-A[i] for i in range(N)]
    heapq.heapify(hq)
    while rest > 0:
    #     temp_idx = A_items[0][1]
    #     while A_items[0][0] >= A_items[1][0]:
    #         rest -= 1
    #         A_items[0][0] //= 2
    #         A[temp_idx] //= 2
    #     idx = 2
    #     while A_items[0][0] < A_items[idx][0]:
    #         idx += 1
    #         if idx >= N-1:
    #             break
    #     u, v = A_items[0], A_items[idx-1]
    #     A_items[idx-1] = u
    #     A_items[0] = v
    # total = sum(A)
        
        max_v = heapq.heappop(hq) * (-1)
        max_idx = A_dic[max_v].pop()
        A[max_idx] //= 2
        if max_v//2 not in A_dic:
            A_dic[max_v//2] = []
        A_dic[max_v//2].append(max_idx)
        heapq.heappush(hq, (max_v//2) * (-1))
        rest -= 1
    total = sum(A)
    


print(total)
### BUGGY CODE ###

def dfs(i, j, s):
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        dfs(k, j + 1, s + k)

ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    for i in range(1, n + 1):
        dfs(i, 1, i)

print(sum(ans))


### FIXED CODE ###

def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            if i + j < x < i + 2 * j:
                result += 1
    return str(result)

ans = []
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    ans.append(calc(n, x))

print("\n".join(ans))
### BUGGY CODE ###

q = int(input())


def lcs(X, Y):
    x_len = len(X)
    y_len = len(Y)
    dp = [[0 for _ in range(y_len+1)] for _ in range(x_len+1)]
    
    for i in range(1, x_len+1):
        for j in range(1, y_len+1):
            if X[i-1] == Y[j-1]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
                               
    return max(max(dp))
    
for _ in range(q):
    X = input()
    Y = input()
    print(lcs(X, Y))

### FIXED CODE ###

q = int(input())

def lcs(X, Y):
    dp = [0]*(len(Y)+1)
    
    for x in X:
        tmp = dp[:]
        for j, y in enumerate(Y):
            if x == y:
                dp[j+1] = tmp[j] + 1
            elif dp[j+1] < dp[j]:
                dp[j+1] = dp[j]
                               
    return dp[-1]
    
for _ in range(q):
    X = input()
    Y = input()
    print(lcs(X, Y))
### BUGGY CODE ###

N,*A = map(int,open(0).read().split())
ans = 1
for i in A:
    ans *= i
print(-1 if ans>10**18 else ans)  


### FIXED CODE ###

N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
        if ans > a:
            print(-1)
            exit()
    print(ans)
### BUGGY CODE ###

from fractions import gcd
from functools import reduce

MOD = 1000000007

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

n = int(input())
a = [int(_) for _ in input().split()]
LCM = reduce(lcm, a)

arr = [0] * n
for i in range(n):
    arr[i] = LCM // a[i]
print(sum(arr) % MOD)

### FIXED CODE ###

from fractions import gcd
from functools import reduce

MOD = 1000000007

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

n = int(input())
a = [int(_) for _ in input().split()]
LCM = reduce(lcm, a)

arr = [LCM // _ for _ in a]
print(sum(arr) % MOD)
### BUGGY CODE ###

def main():
	n,k = map(int,input().split())
	stop = 0
	while stop == 0:
		nabs = abs(n-k)
		if n < nabs:
			stop = 1
			print(n)
		else:
			n = nabs



if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	n,k = map(int,input().split())
	
	mod = n % k
	if mod < k:
		print(min(mod,abs(mod-k)))
	else:
		print(mod)



if __name__ == '__main__':
	main()
### BUGGY CODE ###

N=int(input())
P = list(map(int,input().split()))
ans=0


for i in range(N):
    if min(P[:i+1])==P[i]:
        ans+=1
    else:
        ans+=0
print(ans)

### FIXED CODE ###

N=int(input())
P = list(map(int,input().split()))
ans=0
m=P[0]
 
for i in range(N):
    if m >= P[i]:
        ans += 1
        m = P[i]

print(ans)
### BUGGY CODE ###

if __name__ == "__main__":
    N = int(input())
    nmin = 10**12
    if N == 1:
        print(0)
        exit()
    for n in range(1, N):
        r = N % n
        if r == 0:
            if n + N//n - 2 < nmin:
                nmin = n + N//n - 2

    print(nmin)

### FIXED CODE ###

import math

if __name__ == "__main__":
    N = int(input())
    nsqrt = math.sqrt(N)
    for i in range(int(nsqrt), 0, -1):
        if N % i == 0:
            print(i + N//i - 2)
            exit()
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(a) for a in input().split()]
OneNum = [0] * 40
for a in A:
    for i in range(40):
        OneNum[-1-i] += a%2
        a//=2
        if a == 0: break

def digDP(digit, rem, memo):
    if digit == 39:
        if rem == 0: return OneNum[-1]
        else:
            return max(OneNum[-1], N - OneNum[-1])
    try: return memo[(digit, rem)]
    except KeyError:
        if 2 ** (39 - digit) > rem:
            ans = 2 ** (39-digit) * OneNum[digit] + digDP(digit+1, rem, memo)
            memo[(digit, rem)] = ans
            return ans
        else:
            useDigit = 2 ** (39-digit) * (N-OneNum[digit]) + digDP(digit + 1, rem - (2**(39-digit)), memo)
            notUseDigit = 2 ** (39-digit) * OneNum[digit] + digDP(digit + 1, rem, memo)
            memo[(digit, rem)] = max(useDigit, notUseDigit)
            return max(useDigit, notUseDigit)

memo = {}
print(digDP(0, K, memo))

### FIXED CODE ###

N, K = map(int, input().split())
bitK = format(K, "b").zfill(41)
A = [int(a) for a in input().split()]
DP = [[0, 0] for _ in range(41)] #DP[i][0]は上位i bit目までKと一致、DP[i][1]はK以下
Ones = [0] * 41
for a in A:
    bita = format(a, "b").zfill(41)
    for i in range(41):
        Ones[i] += int(bita[i])

if bitK[0] == "1":
    DP[0][0] = (2 ** 40) * (N - Ones[0])
    DP[0][1] = (2 ** 40) * Ones[0]
else:
    DP[0][0] = (2 ** 40) * Ones[0]
    DP[0][1] = 0

for i in range(1, 41):
    oneNum = Ones[i]
    digit = 2**(40-i)
    if bitK[i] == "1":
        DP[i][0] = DP[i-1][0] + digit * (N - oneNum)
        DP[i][1] = DP[i-1][0] + digit*oneNum
        if DP[i-1][1] > 0:
            DP[i][1] = max(DP[i][1], DP[i-1][1] + digit*max(oneNum, N-oneNum))
    else:
        DP[i][0] = DP[i-1][0] + digit*oneNum
        if DP[i-1][1] > 0:
            DP[i][1] = DP[i-1][1] + digit*max(oneNum, N-oneNum)

print(max(DP[-1]))
### BUGGY CODE ###

#!/usr/bin/env python3

import sys, math, copy
import fractions, itertools
import numpy as np
import scipy

MOD = 10 ** 9 + 7
HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    def mass(n, m, k, l):
        return 100 * n * a + 100 * m * b + k * c + l * d

    def mass_sugar(k, l):
        return k * c + l * d

    def is_within_f(n, m, k, l):
        return mass(n, m, k, l) <= f

    def is_within_e(n, m, k, l):
        waterp100 = n * a + m * b
        return mass_sugar(k, l) <= waterp100 * e

    def density(n, m, k, l):
        waterp100 = n * a + m * b
        return mass_sugar(k, l) / waterp100

    a, b, c, d, e, f = map(int, input().split())
    max_n = f // (100 * a)
    max_m = f // (100 * b)
    max_sugar = f * e / 100.0
    max_k = math.ceil(max_sugar // c)
    max_l = math.ceil(max_sugar // d)

    max_density = -0.1
    nmkl = []
    for n in range(max_n + 1):
        for m in range(max_m + 1):
            if n == m == 0:
                continue
            if not is_within_f(n, m, 0, 0):
                continue
            for k in range(max_k + 1):
                for l in range(max_l + 1):
                    if is_within_f(n, m, k, l) and is_within_e(n, m, k, l):
                        den = density(n, m, k, l)
                        if den > max_density:
                            max_density = den
                            nmkl = [n, m, k, l]

    n, m, k, l = nmkl
    print(mass(n, m, k, l), mass_sugar(k, l))

main()


### FIXED CODE ###

#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

MOD = 10 ** 9 + 7
HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    def mass_water(n, m):
        return 100 * n * a + 100 * m * b

    def mass_sugar(k, l):
        return k * c + l * d

    def mass(n, m, k, l):
        return mass_water(n, m) + mass_sugar(k, l)

    def is_within_f(ms, mw):
        return ms + mw <= f

    def is_within_e(ms, mw):
        return ms * 100 <= mw * e

    def density(ms, mw):
        return ms / mw

    a, b, c, d, e, f = map(int, input().split())
    max_n = f // (100 * a)
    max_m = f // (100 * b)
    max_sugar = f * e / 100.0
    max_k = math.ceil(max_sugar // c)
    max_l = math.ceil(max_sugar // d)

    mass_water_set = set()
    for n in range(max_n + 1):
        for m in range(max_m + 1):
            mw = mass_water(n, m)
            if n + m > 0 and is_within_f(0, mw):
                mass_water_set.add(mw)
    mass_sugar_set = set()
    for k in range(max_k + 1):
        for l in range(max_l + 1):
            mass_sugar_set.add(mass_sugar(k, l))


    max_density = -HUGE
    max_mw = 0
    max_ms = 0
    for mw in mass_water_set:
        for ms in mass_sugar_set:
            if not (is_within_f(ms, mw) and is_within_e(ms, mw)):
                continue
            den = density(ms, mw)
            if den > max_density:
                max_density = den
                max_mw = mw
                max_ms = ms

    print(max_mw + max_ms, max_ms)

main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 7)

# input & solve
N, Q = map(int, input().split())

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

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

dfs(0)

# output
print(*ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 7)

# input & solve
input = sys.stdin.readline
N, Q = map(int, input().split())

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

ans = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

dfs(0)

# output
print(*ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = [int(input()) for i in range(n)]

h.sort()
ans = max(h)
for i in range(n-k+1):
  hi = h[i:i+k]
  ans = min(ans, max(hi) - min(hi))
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
h = [int(input()) for i in range(n)]

h.sort()
ans = max(h)
for i in range(n-k+1):
  ans = min(ans, h[i+k-1] - h[i])
print(ans)
### BUGGY CODE ###

def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


def convertor(string):
    result = ""
    for s in string:
        if s == 'A':
            result += "1"
        elif s == 'C':
            result += "2"
        elif s == 'G':
            result += "3"
        elif s == 'T':
            result += "4"
        else:
            print("ERROR")
    return eval(result)


n = int(input())
d = []
for i in range(n):
    cmd, string = input().split()
    string = convertor(string)
    if cmd == "insert":
        d.append(string)
    else:
        if binarySearch(sorted(d), string):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

n = int(input())
d = {}
for i in range(n):
    cmd, string = input().split()
    if cmd == "insert":
        d[string] = True
    else:
        try:
            if d[string]:
                print("yes")
        except:
            print("no")
### BUGGY CODE ###

mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0 or D.count(0) > 1:
    print(0)
    exit()
cnt_list = [0] * (N-1)
for i in range(0, N-1):
    cnt_list[i] = D.count(i+1)
##print(cnt_list)
ans = 1
reach = False
for l in cnt_list:
    if l == 0:
        reach = True
    if l != 0 and reach == True:
        print(0)
        exit()
for i in range(1, len(cnt_list)):
    if cnt_list[i] == 0:
        break
    ans *= cnt_list[i-1] ** cnt_list[i]
    ans = ans % mod
print(ans)

### FIXED CODE ###

import collections
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
c = collections.Counter(D)
if c[0] != 1:
    print(0)
    exit()
##print(c)
ans = 1
##print(max(D))
for i in range(1, max(D)+1):
    if c[i] == 0:
        ans = 0
        break
    ans *= c[i-1] ** c[i]
    ans = ans % mod
    ##print(ans)
print(ans)