Harryxun/stf_run huggingface dataset:
N,K=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7
p=[]
n=[]
for i in range(N):
    if A[i]<0:
        n.append(A[i])
    else:
        p.append(A[i])
p.sort(reverse=True)
n.sort()
numplus=len(p)
if numplus==0:
    ans=1
    if K%2==1:
        for i in range(1,K+1):
            ans=(ans*n[i*(-1)])%MOD
    else:
        for i in range(K):
            ans=(ans*n[i])%MOD
elif N==K:
    ans=1
    for i in range(N):
        ans=(ans*A[i])%MOD
else:
    if numplus>=K:
        x=numplus
    else:
        if (K-numplus)%2==1:
            x=numplus-1
        else:
            x=numplus
    ans=1
    for i in range(x):
        ans=(ans*p[i])%MOD
    for i in range(K-x):
        ans=(ans*n[i])%MOD
    temp=ans
    bai=1
    while x>1:
        if len(n)<(K-x+2):
            break
        if n[K-x]*n[K-x+1]<p[x-1]*p[x-2]:
            break
        temp=(temp*n[K-x]*n[K-x+1])%MOD
        temp=(temp*pow(p[x-1]*p[x-2],MOD-2,MOD))%MOD
        ans=temp
        x-=2
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7
p=[]
n=[]
for i in range(N):
    if A[i]<=0:
        n.append(A[i])
    else:
        p.append(A[i])
p.sort(reverse=True)
n.sort()
numplus=len(p)
if numplus==0:
    ans=1
    if K%2==1:
        for i in range(1,K+1):
            ans=(ans*n[i*(-1)])%MOD
    else:
        for i in range(K):
            ans=(ans*n[i])%MOD
elif N==K:
    ans=1
    for i in range(N):
        ans=(ans*A[i])%MOD
else:
    if numplus>=K:
        x=K
        if 0 in p:
            zero=p.index(0)
            len(p)-zero-1
    else:
        if (K-numplus)%2==1:
            x=numplus-1
        else:
            x=numplus
    ans=1
    for i in range(x):
        ans=(ans*p[i])%MOD
    for i in range(K-x):
        ans=(ans*n[i])%MOD
    temp=ans
    while x>1:
        if len(n)<(K-x+2):
            break
        if n[K-x]*n[K-x+1]<p[x-1]*p[x-2]:
            break
        temp=(temp*n[K-x]*n[K-x+1])%MOD
        temp=(temp*pow(p[x-1]*p[x-2],MOD-2,MOD))%MOD
        ans=temp
        x-=2
print(ans)
input_n = int(input())
input_a = map(int,input().split())
cnt = 0
end_flg = True

while end_flg:
    for i in range(input_n):

        if input_a[i] % 2 == 0:
            input_a[i] = input_a[i]/2

        else:
            end_flg = False
            break
    if end_flg == False:break
    cnt+=1

print(cnt)

### FIXED CODE ###

input_n = input()
input_a = input().split()
cnt = 0
end_flg = True

while end_flg:
    for i in range(int(input_n)):

        if int(input_a[i]) % 2 == 0:
            input_a[i] = int(input_a[i])/2

        else:
            end_flg = False
            break
    if end_flg == False:break
    cnt+=1

print(cnt)
s = [input() for i in range(3)]
A = s[0]
B = s[1]
K = s[2]

for j in range(K):
  if A >0:
    A -= 1
  elif B >0:
    B -= 1
  else:
    break

print(A, B)

### FIXED CODE ###

i = list(map(int, input().split()))
A = i[0]
B = i[1]
K = i[2]

if K <= A :
    A -= K
elif K <= A + B :
    B -= K - A
    A = 0
else :
    A = 0
    B = 0

print(A, B)
W,H = map(int, input().split())
pic = [input().split() for i in range(H)]
for i in range(H):
  print(''.join(pic[i]))
  print(''.join(pic[i]))

### FIXED CODE ###

H,W = map(int,input().split())
pic = [input().split() for i in range(H)]
for i in range(H):
  print(''.join(pic[i]))
  print(''.join(pic[i]))
n=int(input())
for i in range(n,10**5):
  for j in range(2,10*5):
	if i%j==0:
      print(i)
      quit()

### FIXED CODE ###

n=int(input())
for i in range(n,10**6):
  for j in range(2,int(i**0.5)+1):
    if i%j==0:
      break
  else:
    print(i)
    break
S = input()
count = 0
List = [s for s in S]
for i in List:
  if i = "o":
    count+=1
print(700+100*count)

### FIXED CODE ###

S = input()
count = 0
List = [s for s in S]
for i in List:
  if i == "o":
    count+=1
print(700+100*count)
aaaaaaaaaaaaaaab
aaaaaaaaaaaaaaab

### FIXED CODE ###

n=input()
m=input()
n*=2
if m in n:
    print("Yes")
else:
    print("No")
arr = input() for i in range(4)
count = 0
sum = 0
for fihun in range(int(arr[0]) + 1):
    for hun in range(int(arr[1]) + 1):
        for fi in range(int(arr[2]) + 1):
            sum = fihun * 500 + hun * 100 + fi * 50
            if sum == int(arr[3]):
                count += 1
print(count)


### FIXED CODE ###

arr = [input() for i in range(4)]
count = 0
sum = 0
for fihun in range(int(arr[0]) + 1):
    for hun in range(int(arr[1]) + 1):
        for fi in range(int(arr[2]) + 1):
            sum = fihun * 500 + hun * 100 + fi * 50
            if sum == int(arr[3]):
                count += 1
print(count)
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split()))for i in range(Q)]
dic_A=dict()
sum_A=sum(A)
ans=list()
for i in A:
    if i in dic_A:
        dic_A[i]+=1
    else:
        dic_A[i]=1
for j in range(Q):
    if B[j][0] in dic_A:
        tmp=sum_A+ dic_A[B[j][0]]*(B[j][1]-B[j][0])
        ans.append(tmp)
        sum_A=tmp
        if B[j][1] not in dic_A:
            dic_A[B[j][1]]=dic_A[B[j][0]]
        else:
            dic_A[B[j][1]]+=dic_A[B[j][0]]
        dic_A[B[j][0]]=0
    else:
        ans.append(tmp)
for k in ans:
    print(k)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split()))for i in range(Q)]
dic_A=dict()
sum_A=sum(A)
ans=list()
tmp=0
for i in A:
    if i in dic_A:
        dic_A[i]+=1
    else:
        dic_A[i]=1
for j in range(Q):
    if B[j][0] in dic_A:
        tmp=sum_A+ dic_A[B[j][0]]*(B[j][1]-B[j][0])
        ans.append(tmp)
        sum_A=tmp
        if B[j][1] not in dic_A:
            dic_A[B[j][1]]=dic_A[B[j][0]]
        else:
            dic_A[B[j][1]]+=dic_A[B[j][0]]
        dic_A[B[j][0]]=0
    else:
        if tmp==0:
            ans.append(sum_A)
        else:
            ans.append(tmp)
for k in ans:
    print(k)
N = int(input())
S = list()
for i in range(N):
    S.append(str(input()))

import collections

counter = Counter(S)

max_cnt = max(counter.values())

names = [n for n,c in counter.items() if c==max_cnt]
names.sort()
print(*names, sep='\n')

### FIXED CODE ###

N = int(input())
S = list()
for i in range(N):
    S.append(str(input()))

import collections

counter = collections.Counter(S)

max_cnt = max(counter.values())

names = [n for n,c in counter.items() if c==max_cnt]
names.sort()
print(*names, sep='\n')
a, b, c = map(int, input().split())
if a == b:
    print(c)
elif a == c:
    print(b)
else:
    print(a)

### FIXED CODE ###

n = int(input())
a = int(input())
print(n*n-a)
N = int(input())
X = list(map(int,input().split()))

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

for i in range(N):
    if X[i] <= mid_l:
        print(mid_r)
    else:
        print(min_l)

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

for i in range(N):
    if X[i] <= mid_l:
        print(mid_r)
    else:
        print(mid_l)
a = input().split()
A = int(a[0])
B = int(a[1])
C = int(a[2])
youki1 = B
youki2 = C
youki21 = A-B
youki2 = youki2 - youki21
print(youki2)a = input().split()
A = int(a[0])
B = int(a[1])
C = int(a[2])
print(C-(A-B))

### FIXED CODE ###

a = input().split()
A = int(a[0])
B = int(a[1])
C = int(a[2])
if C-(A-B) >= 0:
    print(C-(A-B))
else:
    print(0)
n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if i < l < k and L[i] + L[j] > L[k] :
        ans += 1
print(ans) 
      


### FIXED CODE ###

n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if L[i] < L[j] < L[k] and L[i] + L[j] > L[k] :
        ans += 1
print(ans)
from itertools import*
_, s = open(0)
print(min(b+c for b, c in zip(*[([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]])))

### FIXED CODE ###

from itertools import*
input();s = input()
b, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]
print(min(x+y for x, y in zip(b, c)))
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

N, M = map(int, readline().split())
AC = 0
WA = 0
li = []
for i in range(M):
    p, s = map(str, readline().decode('utf8').split())
    if p not in li:
        if s != 'AC':
            WA += 1
        else:
            AC += 1
            li.append(p)

print(AC, WA)


### FIXED CODE ###

"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

N, M = map(int, readline().split())
PS = [line.split() for line in readlines()]
AC = [False] * (N + 1)
WA = [0] * (N + 1)

penal = 0
for p, s in PS:
    p = int(p)
    if AC[p]:
        continue
    if s == b'WA':
        WA[p] += 1
    else:
        AC[p] = True
        penal += WA[p]

ac = sum(AC)
print(ac, penal)
a,b,c = map(int,input(.split()))
print(a/(b*2))


### FIXED CODE ###

a,b,c = map(int,input().split())
print(a*b//2)
n = input()
a = list(map(int, input().split()))
for i in range(n):
    while True:
        a[i] = a[i]/2
        if a[i]%2==1:
            break

print(min(a))


### FIXED CODE ###

print(input().count("1"))
a.b = map(int, input().split())
if b%a == 0:
  print(a+b)
else:
  print(b-a)

### FIXED CODE ###

a,b = map(int, input().split())
if b%a == 0:
  print(a+b)
else:
  print(b-a)
n, q = map(int, input().split())
g=[[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)

def dfs(idx,c,res):
    c+=costs[idx]
    res[idx]=c
    for i in g[idx]:
        res = dfs(i,c,res)
    return res

costs = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    costs[p-1]+=x
res = [0]*n
res = dfs(0,0,res)
output=""
for i in range(n):
    output+=(str(res[i])+" ")
print(output[:-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

#def input():
#  return sys.stdin.readline()[:-1]

n,q=map(int,input().split())
cnt=[0]*(n)
g=[[] for _ in range(n)]
for _ in range(n-1): #木グラフの隣接リストを作成
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
for _ in range(q):
    a , b = map(int,input().split())
    a = a - 1
    cnt[a] += b

def dfs(now,prev=-1):
  for next in g[now]:
    if next==prev:
      continue
      
    cnt[next]+=cnt[now]
    dfs(next,now)
dfs(0)
print(*cnt)
n - int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(n-2):
  if (P[i] < P[i+1]) and (P[i+1] < P[i+2]):
    ans += 1
  elif (P[i] > P[i+1]) and (P[i+1] > P[i+2]):
    ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
P = list(map(int, input().split()))
ans = 0
for i in range(n-2):
  if (P[i] < P[i+1]) and (P[i+1] < P[i+2]):
    ans += 1
  elif (P[i] > P[i+1]) and (P[i+1] > P[i+2]):
    ans += 1
print(ans)
N = int(input())
S = [int(input()) for i in range(N)]

print(len(set(S)))

### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]

print(len(set(S)))
x = int(input())

if x = 0:
  print(1)
else:
  print(0)

### FIXED CODE ###

x = int(input())

if x >= 1:
  print(0)
else:
  print(1)
n=int(input())
P=list(map(int,input().split()))
ans=0
if P[0]==1:
  P[0]=P[1]
  P[1]=1
  ans+=1
while True:
  flag=True
  for i in range(1,n):
    if P[i]==i+1:
      P[i]=P[i+1]
      P[i+1]=i+1
      ans+=1
      flag=False
  if flag==True:
    break
print(ans)

### FIXED CODE ###

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

ans=0
for i in range(n-1):
  if P[i]==i+1:
    P[i],P[i+1]=P[i+1],P[i]
    ans+=1
if P[-1]==n:
  ans+=1
print(ans)
n,q = map(int,input().split())
s = input()
ans =[]
j = 0
for i in range(n-1):#どこにACという連続文字列があるかを調べる
    if s[i] == "A" and s[i+1] == "C":
        j += 1
        ans.append(j)
    else:
        ans.append(j)
for i in range(q):
    l,r = map(int, input().split())
    print(ans[r-2]-ans[l]+1)


### FIXED CODE ###

n,q = map(int,input().split())
s = input()
ans =[0]
j = 0
for i in range(n-1):#どこにACという連続文字列があるかを調べる
    if s[i] == "A" and s[i+1] == "C":
        j += 1
        ans.append(j)
    else:
        ans.append(j)
# print(ans)
for i in range(q):
    l,r = map(int, input().split())
    print(ans[r-1]-ans[l-1])
a = [int(input()) for i in range(5)]
(a[0]+a[1])*a[2]/2

### FIXED CODE ###

a = [int(input()) for i in range(3)]
print(int((a[0]+a[1])*a[2]/2))
n=int(input())
a=list(map(int,input().split()))
bbottom=""
btop=""
for i in range(n):
  if i%2==0:
    bbottom+=a[i]
  else:
    btop+=a[i]
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(ans)
       


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
bbottom=[]
btop=[]
for i in range(n):
  if i%2==0:
    bbottom.append(a[i])
  else:
    btop.append(a[i])
ans=btop[::-1]+bbottom
if n%2==1:
  ans=ans[::-1]
print(*ans)
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    prob = [tuple(map(int,input().split())) for _ in range(N)]
    
    #min_Rとmax_Lが同じグループにいる時
    max_L = 0
    min_R = INF
    cnt_max = 0 #L最大を満たすのが何個あるか
    cnt_min = 0 #R最小を満たすのが何個あるか
    for i,(l,r) in enumerate(prob):
        if l == max_L:
            cnt_max += 1
        elif l > max_L:
            cnt_max = 1
            max_L = l
        if r == min_R:
            cnt_min += 1
        elif r < min_R:
            cnt_min = 1
            min_R = r
    
    if cnt_min > 1 and cnt_max > 1:
        max_diff = max(r - l for l,r in prob)
    elif cnt_min > 1:
        max_diff = max(r - l for l,r in prob if l != max_L)
    elif cnt_max > 1:
        max_diff = max(r - l for l,r in prob if r != min_R)
    else:
        max_diff = max(r - l for l,r in prob if (r != min_R) and (l != max_L))
    
    ans1 = max_diff + max(min_R - max_L + 1,0) + 1
    
    #min_Rとmax_Lが違うグループにいる時
    prob.sort(key = lambda x:x[1])
    diff = prob[0][1] - prob[0][0]
    cummax_L = prob[0][0]
    for l,r in prob[1:]:
        diff = max(diff,r - cummax_L)
        cummax_L = max(cummax_L,l)
    
    ans2 = min_R - max_L + diff + 2

    print(max(ans1,ans2,0))
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    prob = [tuple(map(int,input().split())) for _ in range(N)]
    
    if N == 2:
        ans = sum(r - l + 1 for l,r in prob)
        print(ans)
        return 

    #min_Rとmax_Lが同じグループにいる時
    max_L = 0
    min_R = INF
    cnt_max = 0 #L最大を満たすのが何個あるか
    cnt_min = 0 #R最小を満たすのが何個あるか
    for l,r in prob:
        if l == max_L:
            cnt_max += 1
        elif l > max_L:
            cnt_max = 1
            max_L = l
        if r == min_R:
            cnt_min += 1
        elif r < min_R:
            cnt_min = 1
            min_R = r
    
    if cnt_min > 1 and cnt_max > 1:
        max_diff = max(r - l for l,r in prob) + 1
    elif cnt_min > 1:
        max_diff = max(r - l for l,r in prob if l != max_L) + 1
    elif cnt_max > 1:
        max_diff = max(r - l for l,r in prob if r != min_R) + 1
    else:
        max_diff = max(r - l for l,r in prob if (r != min_R) and (l != max_L)) + 1
    
    ans1 = max_diff + max(min_R - max_L + 1,0)
    
    #min_Rとmax_Lが違うグループにいる時
    prob.sort(key = lambda x:(x[1],x[0]))
    cummax_L = prob[0][0]
    ans2 = 0
    for l,r in prob[1:]:
        ans2 = max(ans2,max(r - max_L + 1,0) + max(min_R - cummax_L + 1,0))
        cummax_L = max(cummax_L,l)

    print(max(ans1,ans2))
if __name__ == '__main__':
    main()
import numpy as np

N, K = map(int, input().split())
ub = K * 2
bw = {"B": np.zeros((ub, ub), int), "W": np.zeros((ub, ub), int)}
for i in range(N):
	x, y, c = input().split()
	bw[c][int(x) % ub][int(y) % ub] += 1

def accum_arr(arr):
	acc_h = np.zeros((ub, ub), int)
	acc_v = np.zeros((ub, ub), int)
	acc = np.zeros((ub, ub), int)
	acc_h[:, 0] = arr[:, 0] + arr[:, - (K - 1):].sum(axis=1)
	acc_v[0, :] = arr[0, :] + arr[- (K - 1):, :].sum(axis=0)

	for i in range(1, ub):
		acc_h[:, i] = arr[:, i] + acc_h[:, i - 1] - arr[:, (i - K) % ub]
		acc_v[i, :] = arr[i, :] + acc_v[i - 1, :] - arr[(i - K) % ub, :]

	acc[0][0] = arr[0][0] + arr[0, - (K - 1):].sum() + arr[- (K - 1):, 0].sum() + arr[-(K - 1):, - (K - 1):].sum()

	for j in range(1, ub):
		acc[0][j] = acc[0][j - 1] + acc_v[0][j] - acc_v[0][(j - K) % ub]

	for j in range(ub):
		for i in range(1, ub):
			acc[i][j] = acc[i - 1][j] + acc_h[i][j] - acc_h[(i - K) % ub][j]

	return acc


b_acc = accum_arr(bw["B"])
w_acc = accum_arr(bw["W"])

ans = 0
for x in range(ub):
	for y in range(ub):
		x_cmp = (x + K) % ub
		y_cmp = (y + K) % ub
		tmp_ans = b_acc[x][y] + b_acc[x_cmp][y_cmp] + w_acc[x][y_cmp] + w_acc[x_cmp][y]
		if tmp_ans > ans:
			ans = tmp_ans

print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
ub = K * 2
b = [[0 for j in range(ub + 1)] for i in range(ub + 1)]

def create_bound(p):
	if p - K + 1 >= 0:
		return [(p - K + 1, p + 1)]
	else:
		return [(0, p + 1), ((p - K + 1) % ub, ub)]

for i in range(N):
	x, y, c = input().split()
	nx = int(x) % ub
	ny = (int(y) + (K if c == "W" else 0)) % ub
	for add in [0, K]:
		for xlb, xub in create_bound((nx + add) % ub):
			for ylb, yub in create_bound((ny + add) % ub):
				b[xlb][ylb] += 1
				b[xlb][yub] -= 1
				b[xub][ylb] -= 1
				b[xub][yub] += 1

for i in range(ub):
	for j in range(ub):
		b[i][j + 1] += b[i][j]
for j in range(ub):
	for i in range(ub):
		b[i + 1][j] += b[i][j]
print(max(max(b[i]) for i in range(ub)))
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=input()
    b=[]
    for i in range(n)[::-1]:
        for e in b:
            a[i]=min(a[i],a[i]^e)
        if a[i]:
            if s[i]=="0":
                b+=a[i]
            else:
                print(1)
                break
    else:
        print(0)

### FIXED CODE ###

#一次独立：rankが成分数
import numpy as np
#0-indexed,MSBがma以下の時
def msb(x,ma=59):
    for i in range(ma,-1,-1):
        if (x>>i)&1:
            return i
    return len()
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=input()
    #独立、msb同じものはない
    #逆に異なれば独立
    msbs=[0 for i in range(60)]
    for i in range(n-1,-1,-1):
        now=a[i]
        m=59
        #独立のときfはTrue、独立でない時fはFalse
        while True:
            m=msb(now,m)
            if msbs[m]==0:
                f=True
                break
            now=msbs[m]^now
            if now==0:
                f=False
                break
        if s[i]=="0":
            if f:
                msbs[m]=now
        else:
            if f:
                print(1)
                break
    else:
        print(0)
a = input()
x = a + a*a + a*a*a
print(x)

### FIXED CODE ###

a = int(input())
x = a*a 
y = a*a*a
z =a+x+y

print(z)
a = input()
ar = []
for i in range(3):
    ar.append(a[i]) 
n = len(ar)
ret = 0
for i in range(n+1):
    s = "+"
    tmp = ""
    for j in range(n):
        if (1 & (i >> j)) == 1:
            tmp += ar[j]
            tmp += s
        else:
            tmp += ar[j]
    stmp = tmp.split("+")
    ret += sum(int(k) for k in stmp)
print(int(ret))

### FIXED CODE ###

a = input()
ar = []
for i in range(len(a)):
    ar.append(a[i])
n = len(ar)
ret = 0
for i in range(2**(n-1)):
    s = "+"
    tmp = ""
    for j in range(n):
        if (1 & (i >> j)) == 1:
            tmp += ar[j]
            tmp += s
        else:
            tmp += ar[j]
    stmp = tmp.split("+")
    ret += sum(int(k) for k in stmp)
print(int(ret))
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
N=ni()
A=na()
A.sort()
n=0
ans=0
for i in range(N-1):
    n+=1
    if(A[i]==A[i+1]):
        continue
    else:
        if(n==A[i]):
            n=0
            continue
        elif(n>A[i]):
            ans=n-A[i]
        else:
            ans=n
        n=0

if(A[-1]!=A[-2]):
    ans+=1


print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
N=ni()
A=na()
A.sort()
dic={}
ans=0
for i in A:
    if(i in dic):
        dic[i]+=1
    else:
        dic[i]=1
for key, value in dic.items():
    if(key==value):
        continue
    elif(key>value):
        ans+=value
    else:
        ans+=value-key


print(ans)
import numpy as np
import sys
input = sys.stdin.readline
h, w, d = map(int, input().split())
num = h * w
mass = np.array((0, 0) for _ in range(num + 1))
mp = np.zeros(num+1, dtype=int)
for i in range(h):
    for j, a in enumerate(map(int, input().split())):
        mass[a] = [i, j]
for i in range(d+1, num+1):
    mp[i] = mp[i-d] + np.sum(abs(mass[i]-mass[i-d]))
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(mp[r]-mp[l])


### FIXED CODE ###

import sys
input = sys.stdin.readline
h, w, d = map(int, input().split())
num = h * w
x = [0] * (num + 1)
y = [0] * (num + 1)
mp = [0] * (num + 1)
for i in range(h):
    for j, a in enumerate(map(int, input().split())):
        x[a], y[a] = [i+1, j+1]
for i in range(d+1, num+1):
    mp[i] = mp[i-d] + abs(x[i] - x[i-d]) + abs(y[i] - y[i-d])
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(mp[r]-mp[l])
import sys
sys.setrecursionlimit(1000000)

N = int(input())
X = input()
pc = X.count('1')

mod_plus_1 = int(X, 2) % (pc+1)
mod_minus_1 = int(X, 2) % (pc-1)


def f(x):
    if x == 0:
        return 0
    else:
        return f(x % bin(x).count('1'))+1


for i in range(N):
    if X[i] == '0':
        x = mod_plus_1
        x += 2**(N-1-i) % (pc+1)
        x %= (pc+1)
    else:
        x = mod_minus_1
        x -= 2**(N-1-i) % (pc-1)
        x %= (pc+1)
    if x == 0:
        print(1)
    else:
        print(f(x)+1)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

N = int(input())
X = input()
pc = X.count('1')


if pc == 0:
    print(*[1]*N, sep='\n')
    exit()
elif pc == 1:
    if int(X, 2) == 1:
        for i in range(N-1):
            print(2)
        print(0)
        exit()
    else:
        for i in range(N):
            if i == N-1:
                print(2)
            elif X[i] == '0':
                print(1)
            else:
                print(0)
        exit()

mod_plus_1, mod_minus_1 = 0, 0
for i in range(N):
    mod_plus_1 = (mod_plus_1*2+int(X[i])) % (pc+1)
    mod_minus_1 = (mod_minus_1*2+int(X[i])) % (pc-1)


def f(x):
    if x == 0:
        return 0
    else:
        return f(x % bin(x).count('1'))+1


mods_p1, mods_m1 = [1 % (pc+1)], [1 % (pc-1)]
for i in range(N-1):
    mods_p1.append(mods_p1[-1]*2 % (pc+1))
    mods_m1.append(mods_m1[-1]*2 % (pc-1))
mods_p1 = mods_p1[::-1]
mods_m1 = mods_m1[::-1]


for i in range(N):
    if X[i] == '0':
        x = mod_plus_1 + mods_p1[i]
        x %= (pc+1)
    else:
        x = mod_minus_1 - mods_m1[i]
        x %= (pc-1)

    if x == 0:
        print(1)
    else:
        print(f(x)+1)
H,W  = map(int,input().split())
s = []
ans = 'Yes'
for _ in range(W):
    s.append(input())

for i in range(H-1):
    for j in range(W-1):
        if s[i][j]=='.':
            continue
        else:
            if s[i][j+1]=='.' and s[i+1][j]=='.':
                print('No')
                exit()
print(ans)

### FIXED CODE ###

H,W  = map(int,input().split())
s = []
ans = 'Yes'
for _ in range(H):
    s.append(input())

for i in range(1,H-1):
    for j in range(1,W-1):
        if s[i][j]=='#' and s[i][j+1]==s[i+1][j]==s[i][j-1]==s[i-1][j]=='.':
                print('No')
                exit()
print(ans)