Problem:
 Score : 300 points    Problem Statement You are given a sequence of positive integers of length N , a = (a_1, a_2, ..., a_N) .
Your objective is to remove some of the elements in a so that a will be a good sequence .  Here, an sequence b is a good sequence when the following condition holds true:   For each element x in b , the value x occurs exactly x times in b .   For example, (3, 3, 3) , (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.      Constraints  1 \leq N \leq 10^5  a_i is an integer.  1 \leq a_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_N       Output Print the minimum number of elements that needs to be removed so that a will be a good sequence.        Sample Input 1 4
3 3 3 3      Sample Output 1 1  We can, for example, remove one occurrence of 3 . Then, (3, 3, 3) is a good sequence.       Sample Input 2 5
2 4 1 4 2      Sample Output 2 2  We can, for example, remove two occurrences of 4 . Then, (2, 1, 2) is a good sequence.       Sample Input 3 6
1 2 2 3 3 3      Sample Output 3 0       Sample Input 4 1
1000000000      Sample Output 4 1  Remove one occurrence of 10^9 . Then, () is a good sequence.       Sample Input 5 8
2 7 1 8 2 8 1 8      Sample Output 5 5

Solution (Python):
import numpy as np
from collections import Counter

n = input()
a = np.array([int(i) for i in input().split()])

x = Counter(a)
out = 0
for i in x:
    if(x[i] < i):
        out += x[i]
    else:
        out += x[i] - i

print(out)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)

for a in A:
    d[a]+=1

ans=0
for k in d.keys():
    if d[k]>k:
        ans+=d[k]-k
    elif d[k]<k:
        ans+=d[k]
print(ans)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))

import collections as coll
cnt = coll.Counter(L)
ans = 0
for x in cnt.items():
    if x[0] > x[1]:
        ans += x[1]
    elif x[0] < x[1]:
        ans += x[1] - x[0]
print(ans)

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

kazu = {}

for i in range(len(a)):
  if a[i] not in kazu:
    kazu[a[i]]=1
  else:
    kazu[a[i]]+=1

ans = 0
for i in kazu:
  if i > kazu[i]:
    ans +=kazu[i]
  elif i< kazu[i]:
    ans += kazu[i]-i
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

C = Counter(a)
ans = 0

for i in C:
    if C[i] > i:
        ans += C[i]-i
    elif C[i] < i:
        ans += C[i]

print(ans)

Solution (Python):
from collections import Counter as C
N = int(input())
A = [int(a) for a in input().split()]
X = C(A)
ans = 0
for x in X:
    ans += X[x] if X[x] < x else X[x] - x
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1
num = 0
for k, v in B.items():
    if k <= v:
        num += v - k
    else:  
        num += v
print(num)

Solution (Python):
from collections import Counter

n = int(input())
A = Counter([int(i) for i in input().split()])

count = 0
for k, v in A.items():
    if k < v:
        count += v - k
    elif k > v:
        count += v
        
print(count)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

ans = 0
for i,v in c.items():
    if v > i:
        ans += v - i  
    elif v < i:
        ans += v
print(ans)

Solution (Python):
N = int(input())
Num = list(map(int,input().split()))
ki = []
count = 0
for i in range(N):
    if Num[i] in ki:
        pass
    elif Num[i] > 100000:
        count+=1
    else:
        c = Num.count(Num[i])
        if c > Num[i]:
            count+=(c-Num[i])
        elif c < Num[i]:
            count+=c
        else:
            pass
        ki.append(Num[i])
print(count)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ans = 0
for a, cnt in Counter(A).items():
  if a < cnt:
    ans += cnt - a
  elif a > cnt:
    ans += cnt
print(ans)

Solution (Python):
from collections import Counter

def inpl(): return list(map(int, input().split()))

N = int(input())

ans = 0
for k, v in Counter(inpl()).items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

from collections import Counter
C = Counter(A).most_common()

ans = 0
for (k,v) in C:
    if v<k:
        ans += v
    elif v>k:
        ans += v-k

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
ans = 0
for num, cnt in Counter(a).items():
    if num < cnt:
        ans += cnt-num
    elif num > cnt:
        ans += cnt
print(ans)

Solution (Python):
n = map(int, input().split())
a = list(map(int, input().split()))
d = dict()
finish = []
ans = 0
for x in a:
    if x in finish:
        ans += 1
    else:
        try: d[x] += 1
        except: d[x] = 1
        if d[x] == x:
            finish.append(x)
            del d[x]
print(ans + sum(list(d.values())))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))

dic = {}
for i in a:
    dic[i] = 0

for val in a:
    dic[val] += 1

ans = 0
for key,val in dic.items():
    if key < val:
        ans += val - key
    elif key >val:
        ans += val


print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
data = {}
ans = 0
for i in a:
    if i not in data:
        data[i] = 1
    else:
        data[i] += 1

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

print(ans)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
A.sort()
A.append(0)
index = 0
ans = 0

while index <= n-1:
    x = A[index]
    j = index+1
    while True:
        if A[j] != x:
            if j-index < x:
                ans += j-index
                index = j
                break
            elif j-index == x:
                index = j
                break
            elif j-index > x:
                ans += j-index-x
                index = j
                break
        else:
            j += 1

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
a=Counter(input().split())
ans=0
for i,j in a.items():
    i=int(i)
    if i>j:
        ans+=j
    elif i<j:
        ans+=j-i
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
a=Counter(input().split())
count=0
keys,counts=zip(*a.most_common())
for i,j in zip(keys,counts):
    i=int(i)
    if i>j:
        count+=j
    elif i<j:
        count+=j-i
print(count)

Solution (Python):
import sys
N = int(input())

a = [int(n) for n in input().split()]

dic = {}
for ak in a:
    if not(ak in dic):
        dic[ak] = 1
    else:
        dic[ak] += 1
ans = 0
for k in dic.keys():
    if(dic[k] - k > 0):
        ans+=dic[k] - k
    elif(dic[k] - k < 0):
        ans+=dic[k]
print(ans)

Solution (Python):
from collections import Counter

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

a = Counter(a)

total = 0

for k, v in a.items():
    if k > v:
        total += v
    else:
        total += v-k

print(total)

Solution (Python):
import collections

N = int(input())
a = [int(i) for i in input().split()]
ans = 0

num = collections.Counter(a).most_common()

for a, b in num:
    if b < a:
        ans += b
    elif a < b:
        ans += b-a
print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))

d = {}
for i in range(N):
  if(a[i] not in d):
    d[a[i]] = 1
  else:
    d[a[i]] += 1
cnt = 0
for k, v in d.items():
  if(k > v):
    cnt += v
  elif(k < v):
    cnt += v - k
print(cnt)

Solution (Python):
import collections
N = input()
a = map(int, raw_input().split())

c = collections.Counter(a)
res = 0
for k, v in c.items():
  if k > v:
    res += v
  elif k < v:
    res += v - k
print res

Solution (Python):
b = {}
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    if a[i] not in b:
        b[a[i]] = 1
    else:
        b[a[i]] += 1
count = 0
for i in b:
    if b[i] < i:
        count += b[i]
    else:
        count += b[i] - i

print(count)

Solution (Python):


def main():
    N = int(input())
    sa = input().split(' ')
    a = [int(s) for s in sa]

    d = dict()
    for k in a:
        if k in d:
            d[k] = d[k] + 1
        else:
            d[k] = 1

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


    print(c)


if __name__ == '__main__':
    main()

Solution (Python):
def abc082_c():
    from collections import Counter

    _ = int(input())
    a = list(map(int, input().split()))
    ans = 0
    a_count = Counter(a)

    for num in a_count:
        if num <= a_count[num]:
            ans += (a_count[num] - num)
        else:
            ans += a_count[num]

    print(ans)


abc082_c()

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
dic = {}
i_list = []
for a in a_list:
    dic[a] = 0
for a in a_list:
    dic[a] += 1
    if dic[a] == 1:
        i_list.append(a)
ans = 0
for i in i_list:
    p = dic[i] - i 
    if p >= 0:
        ans += p
    else:
        ans += dic[i]
print(ans)

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    counts = Counter(aa)
    res = sum(v if v < k else v - k for k, v in counts.items())
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]

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

res = 0
for k, v in summary.items():
    if k > v:
        res += v
    else:
        res += min(v - k, v)

print(res)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
count = {}
ans = 0
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
for i,c in count.items():
    if i > c:
        ans += c
    elif i < c:
        ans += c - i
print(ans)

Solution (Python):
from collections import Counter
ans=0
n=int(input())
a=list(map(int,input().split()))
a_tmp=dict(Counter(a).most_common())
for i,j in a_tmp.items():
    i=int(i)
    j=int(j)
    if i==j:
        pass
    elif i<j:
        ans+=j-i
    else:
        ans+=j
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()] 
count = {}
ans = 0
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
for i,c in count.items():
    if i > c:
        ans += c
    elif i < c:
        ans += c - i
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A).items()
count = 0
for e in c:
    num = e[1] - e[0]
    if num < 0:
        count += e[1]
    else:
        count += num
print(count)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
count = {}
ans = 0
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
for i, c in count.items():
    if i > c:
        ans += c
    elif i < c:
        ans += c - i
print(ans)

Solution (Python):
import collections

n = int(input())

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

arr3 = collections.Counter(arr)

flg = 1
ans = 0

for i,j in arr3.items():
	if i != j:
		if i < j:
			ans += j - i
		else:
			ans += j
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
ans = 0 
c = Counter(list(map(int, input().split())))

for key, value in c.items():
    if key < value:
        ans += value-key
    elif key > value:
        ans += value
print(ans)

Solution (Python):
import collections

def main() :
	N = int(input())
	li = [int(i) for i in input().split()]

	c = collections.Counter(li)

	total_count = 0
	for key in c.keys() :
		count = c[key]

		if (count == key) :
			continue
		elif (count > key) :
			total_count += (count - key)
		else  :
			
			total_count += count

	print(total_count)


main()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

count = {}
for i in A:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1

ans = 0
for i, j in count.items():
    if i > j:
        ans += j
    elif i < j:
        ans += j - i

print(ans)

Solution (Python):
import collections

N = int(input())
a = [int(i) for i in input().split(" ")]
c = collections.Counter(a)
ans = 0

for key,val in c.items():
    d = val
    if val >= key:
        d = min(val-key,val)
    ans += d

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
cnt=0
L=[0 for i in range(100005)]
for i in range(N):
    if A[i]<=100000:
        L[A[i]]+=1
    else:
        cnt+=1
    
for j in range(100002):
    
    if L[j]==j:
        pass
    elif L[j]<j:
        cnt+=L[j]
    elif L[j]>j:
        cnt+=L[j]-j
print(cnt)

Solution (Python):
N = int(input())
table={}
for _ in input().split():
    i = int(_)
    if i in table.keys():
        table[i] += 1
    else:
        table[i] = 1
ans = 0
for k, v in table.items():
    if k > v:
        ans += v
    else:
        ans += v-k
print(ans)

Solution (Python):
import collections
count = 0
N = int(input())
a = list(map(int,input().split(" ")))
c = collections.Counter(a)
C = c.most_common()
for i in C:
    A = i[0]
    B = i[1]
    if A < B:
        count += B-A
    elif A == B:
        continue
    else:
        count += B
print(count)

Solution (Python):

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

a.sort()

ans = 0
for i, ai in enumerate(a):
    
    if i == 0:
        view = ai
        cnt = 0
    elif ai > view:
        if cnt > view: ans += cnt - view
        elif cnt < view: ans += cnt
        view = ai
        cnt = 0
    
    cnt += 1
else:
    if cnt > view: ans += (cnt - view)
    elif cnt < view: ans += cnt

print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
a.append(-1)
cost = 0
target = a[0]
start = 0

for i in range(len(a)):
    
    localCost = 1000000
    if a[i] != target:
        if i - start == target:
            localCost = 0
        elif i - start > target:
            localCost = i - start - target
        cost += min(localCost, i - start)
        start = i
        target = a[i]
        
print(cost)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=b.most_common()
x=0
for i in range(len(c)):
  if c[i][0]>c[i][1]:x+=c[i][1]
  elif c[i][0]<c[i][1]:x+=c[i][1]-c[i][0]
print(x)

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))

ac = collections.Counter(a)

ans = 0
for i in ac.keys():
    if ac[i] < i:
        ans += ac[i]
    else:
        ans += (ac[i] - i)

print(ans)

Solution (Python):
import collections

ans = 0
N = int(input())
a = [int(i) for i in input().split()]

dic = collections.Counter(a).most_common()
for a, b in dic:
    if a <= b:
        ans += b-a
    else:
        ans += b
print(ans)

Solution (Python):
n = int(input())
a = input().split()
a = [int(m) for m in a]

a.sort()
sym = 0
symc = 0
delc = 0
for i in range(n):
    if i == 0 and n == 1:
        if a[i] == 1:
            delc = 0
        else:
            delc = 1
    elif i == 0:
        sym = a[i]
        symc += 1
    elif a[i] != a[i - 1]:
        if symc < a[i - 1]:
            delc += symc
        elif symc > a[i - 1]:
            delc += symc - a[i - 1]
        sym = a[i]
        symc = 1
        if i == n - 1:
            if symc < a[i]:
                delc += symc
            elif symc > a[i]:
                delc += symc - a[i]
    elif i == n - 1:
        symc += 1
        if symc < a[i]:
            delc += symc
        elif symc > a[i]:
            delc += symc - a[i]
    else:
        symc += 1

print(delc)

Solution (Python):
import sys
import collections
input=sys.stdin.readline

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)

a=0
for k,v in s.items():
    if k>v:
        a+=v
    else:
        a+=v-k
print(a)

Solution (Python):
import sys
import collections
input=sys.stdin.readline

n=int(input())
l=list(map(int,input().split()))
li=collections.Counter(l)

a=0
for k,v in li.items():
    if k>v:
        a+=v
    else:
        a+=v-k
print(a)

Solution (Python):
def 解():
    iN = int(input())
    dA = {}
    for a in map(int,input().split()):
        if a in dA:
            dA[a] += 1
        else:
            dA[a] = 1
    iC = 0
    for k,v in dA.items():
        if k > v:
            iC += v
        elif k < v:
            iC += v - k
    print (iC)
解()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1
ans = 0
for i in d:
    if d[i] < i:
        ans += d[i]
    if d[i] > i:
        ans += d[i] - i
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mapa = {}
for i in range(n):
    if a[i] in mapa:
        mapa[a[i]] += 1
    else:
        mapa[a[i]] = 1
count = 0
for i in mapa:
    if i < mapa[i]:
        count += mapa[i] - i
    elif i > mapa[i]:
        count += mapa[i]
print(count)

Solution (Python):
import collections
N = int(input())
a = [int(i) for i in input().split()]
hint = collections.Counter(a)
b = hint.most_common()
ans = 0
for val, num in b:
    if val > num:
        ans += num
    elif val < num:
        ans += num-val
print(ans)

Solution (Python):
import collections
n = int(input())
a =list(map(int,input().split()))
col = collections.Counter(a)
a = set(a)
cnt = 0
for letter in a:
    if col[letter]>letter:
        cnt += col[letter] - letter
    elif col[letter]<letter:
        cnt += col[letter]
print(cnt)

Solution (Python):
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
D = defaultdict(int)

for i in range(N):
    D[A[i]] += 1

delete = 0
for d in D:
    if d < D[d]:
        delete += D[d] - d
    elif d > D[d]:
        delete += D[d]
print(delete)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a).most_common()
ans=0
for i in range(len(b)):
    if b[i][0]>b[i][1]:
        ans +=b[i][1]
    else:
        ans +=b[i][1]-b[i][0]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = set(A)

result = {}
for b in B:
    result[b] = 0
for a in A:
    result[a] += 1

count = N
for b in B:
    if result[b] >= b:
        count -= b

print(count)

Solution (Python):

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

dict = {}
for a in an:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

remove_num = 0

for k,v in dict.items():
    if k > v:
        remove_num += v
    else:
        remove_num += v - k

print(remove_num)

Solution (Python):
N = int(input())
a_list = list(map(int, input().split( )))
import collections
a_c=collections.Counter(a_list)


a_val, a_count=zip(*a_c.most_common())

ans =0
for i in range(len(a_val)):
	if a_val[i] > a_count[i]:
		ans += a_count[i]
	elif a_val[i] < a_count[i]:
		ans += a_count[i] - a_val[i]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
num_dict = {}
for a in A:
    if a in num_dict:
        num_dict[a] += 1
    else:
        num_dict[a] = 1

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

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

b = set(a)

hoge = {}

for x in b:
    hoge[x] = 0

for x in a:
    hoge[x] += 1

ans = n
for x in b:
    if hoge[x] >= x:
        ans -= x

print(ans)

Solution (Python):
from collections import defaultdict

def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

n = getN()
seq = getList()
bucket = defaultdict(int)

for num in seq:
    bucket[num] += 1

ans = 0
for i in (bucket.keys()):
    num = bucket[i]
    if num != 0:
        if num < i:
            ans += num
        elif num > i:
            ans += num -i

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
ans = 0

for e in C:
    if C[e] >= e:
        ans += C[e]-e
    else:
        ans += C[e]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
D = {}
for i in A :
    if i in D :
        D[i] += 1
    else :
        D[i] = 1
KEY = list(D.keys())
ITEM = list(D.values())
ans = 0
for i in range(len(KEY)) :
    if KEY[i] <= ITEM[i] :
        ans += ITEM[i]-KEY[i]
    else :
        ans += ITEM[i]
print(ans)

Solution (Python):



def main():
    from collections import Counter

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

    for key, value in a.items():
        if key < value:
            ans += value - key
        elif key > value:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ctr = Counter(A)

ans = 0
for k,v in ctr.items():
    if v < k:
        ans += v
    else:
        ans += v-k
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

from collections import Counter
counter=Counter(A)

ANS=0

for i in counter:
    if counter[i]==i:
        continue
    elif counter[i]>i:
        ANS+=counter[i]-i
    else:
        ANS+=counter[i]

print(ANS)

Solution (Python):
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

n = ni()
a = list(li())

cnt = Counter(a)

ans = 0

for k,v in cnt.items():
    if v > k:
        ans += (v-k)
        
    elif v < k:
        ans += v
        
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ctr = Counter(A)

ans = 0
for k,v in ctr.items():
    if v < k:
        ans += v
    else:
        ans += v-k
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
cnt = Counter(a)

c = 0
for k,v in cnt.items():
    if v >= k:
        c += v-k
    else:
        c += v
print(c)

Solution (Python):
import collections
n=int(input())
a=[int(i) for i in input().split()]


ans=0

l=collections.Counter(a)

for i,j in l.most_common():
    if int(i)<j:
        ans+=j-int(i)
    elif int(i)>j:
        ans+=j
        
print(ans)

Solution (Python):

N=int(input())
a_sorted=sorted(list(map(int,input().split())))

Allowable_original=0
Allowable_count=0
Delete_count=0

if N==1:
    if a_sorted[0]==1:
        print(0)
    else:
        print(1)
    exit()

for i in range(N):
    
    if i==0:
        
        Allowable_original=a_sorted[0]
        Allowable_count=Allowable_original-1
        continue

    
    
    if a_sorted[i]==a_sorted[i-1]:
        
        Allowable_count-=1
    
    if a_sorted[i]!=a_sorted[i-1]:
        
        
        if Allowable_count>0:
            
            Delete_count+=Allowable_original-Allowable_count
        
        else:
            
            Delete_count-=Allowable_count
        
        Allowable_original = a_sorted[i]
        Allowable_count = Allowable_original - 1
    
    if i==N-1:
        
        
        if Allowable_count>0:
            
            Delete_count+=Allowable_original-Allowable_count
        
        else:
            
            Delete_count-=Allowable_count

print(Delete_count)

Solution (Python):
dic={}
N=int(input())
for x in map(int,input().split()):
    if dic.get(x,'a')=='a':
        dic[x]=-x+1
    else:
        dic[x]+=1
ans=0
for k,v in dic.items():
    if v<0:
        ans+=k+v
    else:
        ans+=v
print(ans)

Solution (Python):
n = int(input())
list_a = list(map(int, input().split()))
dict_a = {}
for number in list_a:
    try:
        dict_a[number] += 1
    except KeyError:
        dict_a[number] = 1
count = 0
for key,value in dict_a.items():
    if key > value:
        count += value
    else:
        count += value - key
print(count)

Solution (Python):
n = int(input())
listA = list(map(int, input().split()))
listA.sort()

remCount=0
beforeN =0
index=0
count=0
while index < len(listA):
    if index==0:
        beforeN = listA[index]
        count+=1
    elif beforeN == listA[index]:
        count+=1
    else:
        if count == beforeN:
            pass
        elif count > beforeN:
            remCount+=(count-beforeN)
        else:
            remCount+=count
        beforeN = listA[index]
        count=1
    index+=1
if count == beforeN:
    pass
elif count > beforeN:
    remCount+=(count-beforeN)
else:
    remCount+=count
            
print(remCount)

Solution (Python):
from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
C = defaultdict(int)
for a in A:
  C[a] += 1
cnt = 0
for k, v in C.items():
  cnt += v - k if v >= k else v
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
D = {}
for i in A :
    if i in D :
        D[i] += 1
    else :
        D[i] = 1
answer = 0
for key, value in D.items() :
    if key > value :
        answer += value
    else :
        answer += value-key
print(answer)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
cnt = 1
key = a[0]
ans = 0
while True:
    if i >= len(a):
        break
    if key == a[i]:
        cnt += 1
    else:
        if key != cnt:
            if cnt > key:
                ans += cnt - key
            else:
                ans += cnt
        cnt = 1
        key = a[i]
    
    i += 1

if key != cnt:
    if cnt > key:
        ans += cnt - key
    else:
        ans += cnt

print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

n_cnt = {}
for n in a:
    if n not in n_cnt:
        n_cnt[n] = -n+1
    else:
        n_cnt[n] += 1

print(sum([val if val >=0 else key+val for key, val in n_cnt.items()]))

Solution (Python):
from collections import Counter
N, *A = map(int, open(0).read().split())
print(sum(c - x * (c >= x) for x, c in Counter(A).items()))

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

nums = {}
for i in range(n):
    if not a[i] in nums.keys():
        nums[a[i]] = 1
    else:
        nums[a[i]] += 1

ans = 0
for k in nums.keys():
    if nums[k] > k:
        ans += nums[k]-k
    elif nums[k] < k:
        ans += nums[k]
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

cnt = Counter(a)
ans = 0

for ai, num in cnt.items():
  if num >= ai:
  	ans += num - ai  
  else:
    ans += num

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
a = [int(v) for v in input().split()]
cnt = Counter(a)
ans = 0

for k, v in cnt.items():
    if k > v:
        ans += v
    elif k < v:
        ans += v - k

print(ans)

Solution (Python):


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

    
    ans = 0
    a_set = set(a_list)

    for a in a_set:
        c = a_list.count(a) 
        if c < a:
            ans += c
        elif c > a:
            ans += c-a
    print(ans)

def main2():
    N = int(input())
    a_list = list(map(int, input().split()))
    ans = 0

    import collections
    count_dict = collections.Counter(a_list) 

    for key in count_dict:
        diff = key - count_dict[key]
        if diff == 0:
            continue
        elif diff > 0:
            ans += count_dict[key]
        elif diff < 0:
            ans += abs(diff)
    print(ans)



if __name__ == "__main__":
    main2()

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)

ans = 0
for n,c in c.items():
    if c < n:
        ans += c
    elif n < c:
        ans += c - n
print(ans)

Solution (Python):
import collections

N = int(input())
a = [int(i) for i in input().split()]



c = collections.Counter(a)

ans = 0
for key in list(c.keys()):
    if c[key] > key:
        ans += c[key] - key
    elif key > c[key]:
        ans += c[key]

print(ans)

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
D=dict()
for i in range(N):
    if a[i] in D:
        D[a[i]]+=1
    else:
        D[a[i]]=1
ans=0
for num in D:
    if num<=D[num]:
        ans+=D[num]-num
    else:
        ans+=D[num]
print(ans)

Solution (Python):
N = int(input())
a_list = map(int, input().split())

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

result = 0
for item, item_count in count.items():
    if item <= item_count:
        result += item_count - item
    else:
        result += item_count

print(result)

Solution (Python):
from collections import Counter

N = int(input())
a = [int(x) for x in input().split()]

c = Counter(a)
ans = 0
for k, v in c.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = [int(ai) for ai in input().split()]
c = Counter(a).most_common()
r = 0
for k, v in c:
    if k <= v:
        r += v - k
    else:
        r += v
print(r)

Solution (Python):
import collections
N = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
ans = 0
for i in c:
    if c[i] < i:
        ans += c[i]
    elif c[i] > i:
        ans += c[i] - i
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
CA = Counter(A)
sum = 0
for keys, values in CA.items():
    if int(keys) > values:
        sum += values
    else:
        sum += (values - keys)
print(sum)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

uni_A = list(set(A))
cnt_dict = {}
for uni_a in uni_A:
    cnt_dict[uni_a] = 0



del_count = 0
for a in A:
    cnt_dict[a] += 1
    if cnt_dict[a] > a:
        del_count += 1

for key in cnt_dict.keys():
    if cnt_dict[key] < key:
        del_count += cnt_dict[key]

print(del_count)

Solution (Python):
from collections import Counter
from scipy.misc import comb
N=int(input())
a=map(int, input().split())
counter=Counter(a)
ckeys=list(counter.keys())
ans=0
for i in ckeys:
    if i<counter[i]:
        ans+=min(counter[i]-i, counter[i])
    elif i>counter[i]:
        ans+=counter[i]
print(ans)