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):
from collections import Counter

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

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

print(ans)

Solution (Python):
n = int(input())
s = list(map(int,input().split()))
t = {}
o = 0
for i in range(n):
    if s[i] not in t.keys():
        t[s[i]] = 1
    else:
        t[s[i]] += 1

for i,j in t.items():
    if i > j:
        o += j
    else:
        o += j - i

print(o)

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
A = LI()

counts = collections.Counter(A)

result = 0
for c in counts:
    if c < counts[c]:
        
        result += counts[c] - c
    elif c > counts[c]:
        
        result += counts[c]
print(result)

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

d = {}
for i in a:
    d[i] = d[i] + 1 if d.get(i) else 1

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

Solution (Python):
import collections
input()
c = collections.Counter(list(map(int,input().split())))
ans = 0
for i,j in c.items():
        if j >= i:
            ans += j - i
        else:
            ans += j
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
key = list(c.keys())
val = list(c.values())
ans = 0
for i, j in zip(key, val):
    if i > j:
        ans += j
    else:
        ans += j - i
print(ans)

Solution (Python):
import collections

N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
ans=0
for k,v in c.items():
    if v>=k:
        ans+=v-k
    else:
        ans+=v
print(ans)

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    if a[0] != 1:
        print(1)
        exit()
    else:
        print(0)
        exit()
a.sort()
A = 0
c = 0
while True:
    A = a[0]
    if len(a) > 1:
        for i in range(1, len(a)):
            if a[i] != A:
                del a[:i]
                if i >= A:
                    c += i - A
                else:
                    c += i
                break
            elif i == len(a) - 1:
                if i + 1 >= A:
                    c += i + 1 - A
                else:
                    c += i + 1
                print(c)
                exit()
    else:
        print(c + 1)
        exit()

Solution (Python):
from collections import defaultdict

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

c = defaultdict(int)
for ai in a:
    c[ai] += 1

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    if a[0] != 1:
        print(1)
        exit()
    else:
        print(0)
        exit()
a.sort()
A = 0
c = 0
while True:
    try:
        
        A = a[0]
        if len(a)>1:
            for i in range(1, len(a)):
                if a[i] != A:
                    
                    
                    del a[:i]
                    if i >= A:
                        c += i - A
                    else:
                        c += i
                    
                    break
                elif i == len(a) - 1:
                    if i + 1 >= A:
                        c += i + 1 - A
                    else:
                        c += i + 1
                    print(c)
                    exit()
        else:
            print(c + 1)
            exit()
    except IndexError:
        break

Solution (Python):


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

set_a = set(a)
a.sort()
k = 0
p = 0
ans = 0
for a_ in set_a:
    s = a[k]
    while True:
        if k<len(a) and a[k]==s:
            k+=1
            p+=1
        else:
            if p>=s:
                ans+=p-s
            else:
                ans+=p
            p=0
            break
print(ans)

Solution (Python):
n = int(input())
argv = input().split()

dic = {}
for a in argv:
    i = int(a)
    v = dic.get(i, 0)
    dic[i] = v + 1

count = 0
for k in dic.keys():
    size = dic.get(k)
    if k < size:
        count += size - k
    elif k > size:
        count += size

print(count)

Solution (Python):
import collections
n = int(input())
a = [int(i) for i in input().split()]
l = collections.Counter(a)
c = 0
for k, v in l.items():
    if k < v:
        c += v - k
    elif k > v:
        c += v
print(c)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int,input().split()))
D = Counter(A)
res = 0
for i,v in D.items():
    if i > v:
        res += v
    elif i < v:
        res += v-i
print(res)

Solution (Python):
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
ans = 0
for i in ac:
    if ac[i] >= i:
        ans += ac[i] - i
    else:
        ans += ac[i]
print(ans)

Solution (Python):
from collections import Counter

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

A = Counter(a)

num = len(set(a))
count = 0

D = A.most_common()
for i in range(num):
    if D[i][0] > D[i][1]:
        count += D[i][1]
    else:
        count += D[i][1] - D[i][0]

print(count)

Solution (Python):
n = int(input())

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

d = dict()

for i in range(n):
    if d.__contains__(a[i]):
        d[a[i]]+=1
    else:
        d[a[i]] =1
res = 0
for num,cnt in list(d.items()):
    if cnt>=num:
        res += cnt-num
    else:
        res += cnt 

print(res)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
set_a = set(a)
a.sort()
k = 0
p = 0
ans = 0
for a_ in set_a:
    s = a[k]
    while True:
        if k<len(a) and a[k]==s:
            k+=1
            p+=1
        else:
            if p>=s:
                ans+=p-s
            else:
                ans+=p
            p=0
            break
print(ans)

Solution (Python):
from collections import Counter

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

answer = 0
for k,v in Counter(A).items():
  answer += (v-k) if v >=k else v

print(answer)

Solution (Python):
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    count = Counter(a)
    return str(sum([v if int(k) > v else v - int(k) for k, v in count.items()]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
ans=0
before=a[0]
cnt=1
for i in range(1,n):
    if a[i]==before:
        cnt+=1
    else:
        if before<cnt:
            ans+=abs(cnt-before)
        elif before>cnt:
            ans+=cnt
        before=a[i]
        cnt=1
if before<cnt:
    ans+=abs(cnt-before)
elif before>cnt:
    ans+=cnt
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
dic = {}
for a in A:
    dic.setdefault(a, 0)
    dic[a] += 1
ans = 0
for k, v in dic.items():
    if k == v:
        continue
    if k > v:
        ans += v
    else:
        ans += (v - k)
print(ans)

Solution (Python):
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
ans = 0
for k, v in c.items():
    if v<k: ans+=v
    else: ans+=v-k
print(ans)

Solution (Python):
from collections import Counter

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

D = Counter(A)

res = 0
for i in D.items():
    if i[0] < i[1]:
        res += i[1]-i[0]
    elif i[0] > i[1]:
        res += i[1]

print(res)

Solution (Python):


"""
Created on 2019/3/21
Solved on 2019/3/
@author: shinjisu
"""






def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] 

def getIntMat(n, m):  
    
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    A.sort()
    d.dmp((A), 'A')
    i = 0
    dlt = 0
    while i < N:
        k = 1
        while i+k < N and A[i] == A[i+k]:
            k += 1
            if i+k == N:
                break
        if A[i] < k:
            dlt += k - A[i]
        elif A[i] > k:
            dlt += k
        i += k   
        d.dmp((dlt), 'dlt')
    return dlt


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Solution (Python):
from sys import exit
import math
N = int(input())
dic = {}
a = [int(n) for n in input().split()]
for e in a:
    if e in dic:
        dic[e]+=1
    else:
        dic[e] = 1
ans = 0
for k in dic.keys():
    if k < dic[k]:
        ans+=dic[k]-k
    elif k > dic[k]:
        ans+=dic[k]
    else:
        continue
print(ans)

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

Solution (Python):
n=input()
dc=dict()
for j in input().split():
    i=int(j)
    if i in dc:
        dc[i]+=1
    else:
        dc[i]=1
ans=0
for i in dc:
    if dc[i]>i:
        ans+=dc[i]-i
    elif dc[i]<i:
        ans+=dc[i]
print(ans)

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

ans = 0
d = {}

for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

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

print(ans)

Solution (Python):
from collections import Counter

N = int(input())

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


def main():
    
    
    print(sum([v - k if k <= v else v for k, v in an.items()]))

    return


main()

Solution (Python):
from collections import Counter

from sys import stdin

input = stdin.readline

N = int(input())

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


def main():
    
    
    print(sum([v - k if k <= v else v for k, v in an.items()]))

    return


main()

Solution (Python):
def good_sequence(N: int, A: list) -> int:
    freq = {}
    for a in A:
        freq.setdefault(a, 0)
        freq[a] += 1

    return sum(f if f < n else f - n for n, f in freq.items())


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = good_sequence(N, A)
    print(ans)

Solution (Python):
from collections import Counter

def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    counter = Counter(a)
    s = 0
    for x, c in counter.most_common():
        if c > x:
            s += c - x
        elif c < x:
            s += c
    return s

main()

Solution (Python):


import itertools
import collections
import bisect
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = collections.Counter(A)

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

if __name__ == '__main__':
    main()

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

ans = 0

T = [0]*(N+1)
for x in a:
  if x<=N:
    T[x] += 1
  else:
    ans += 1
for i in range(N+1):
  if T[i]>0:
    if T[i]>=i:
      ans += T[i]-i
    else:
      ans += T[i]
print ans

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=IL()
Ad={}
for a in A:
    if a in Ad:
        Ad[a]+=1
    else:
        Ad[a]=1
ans=0
for key in Ad.keys():
    if Ad[key]<key:
        ans+=Ad[key]
    else:
        ans+=Ad[key]-key
print(ans)

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

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, 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):
N = int(input())
a = list(map(int,input().split()))
a.sort()
now = 0
num = 0
ans = 0
for i in range(N):
    if now != a[i]:
        if num < now:
            ans += num
        else:
            ans += num - now
        now = a[i]
        num = 1
    else:
        num += 1
if num < now:
    ans += num
else:
    ans += num-now
print(ans)

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007


"""
a, b = LI()
print((a+b+1)//2)
"""


"""
a = S()
a = a[:-1]
b = S()
b = b[:-1]
a.sort()
b.sort(reverse=True)
if a < b:
    print("Yes")
else:
    print("No")
"""


n = I()
a = LI()
a.sort()
seta = set(a)
ans = 0
for i in seta:
    x = bisect.bisect_right(a,i) - bisect.bisect_left(a,i)
    if x != 0 and x >= i:
        ans += x - i
    else:
        ans += x
print(ans)

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

Solution (Python):
import math

def A():
    a, b = [int(x) for x in input().split()]
    print(math.ceil((a + b)/2))

def B():
    a = ''.join(sorted(list(input()), key=lambda x:ord(x)))
    b = ''.join(sorted(list(input()), key=lambda x:-ord(x)))
    if a < b:
        print('Yes')
    else:
        print('No')

def C():
    N = input()
    A = [x for x in input().split()]
    counter = {}

    for a in A:
        if(a in counter):
            counter[a] += 1
        else:
            counter[a] = 1
    remove_count = 0
    for key in counter:
        if counter[key] - int(key) >= 0:
            remove_count += counter[key] - int(key)
        else:
            remove_count += counter[key]
    print(remove_count)
C()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    a,b = LI()
    print(math.ceil((a+b)/2))


def B():
    s = S()
    t = S()
    s.sort()
    t.sort()
    t = t[::-1]
    l = [s,t]
    l.sort()
    if s == t:
        print("No")
    elif l[0] == s:
        print("Yes")
    else:
        print("No")

def C():
    n = I()
    d = defaultdict(int)
    a = LI()
    for i in a:
        d[i] += 1
    ans = 0
    for i in d.keys():
        if i <= d[i]:
            ans += d[i]-i
        else:
            ans += d[i]
    print(ans)

def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    B = [0] * (N+1)
    c = 0
    for a in A:
        if a > N:
            c += 1
        elif B[a] < a:
            B[a] += 1
        else:
            c += 1

    for i in range(N+1):
        if B[i] < i:
            c += B[i]

    print(c)


if __name__ == '__main__':
    main()

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


count = len([i for i in a if i > 10**5])
a = [e for e in a if e <= 10**5]
dic = list(set(a))
for x in dic:
    if a.count(x) > x:
        count+= a.count(x) - x
    elif a.count(x) < x:
        count += a.count(x)
print(count)

Solution (Python):
from collections import Counter
n=int(input())
a=tuple([int(i) for i in input().split()])
cnt=dict(Counter(a))
ans=0
for i,j in zip(cnt.keys(),cnt.values()):
    if i>j:
        ans+=j
    elif i!=j:
        ans+=j-i
print(ans)

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

count = 0
for e in d:
    if e < d[e]:
        count += d[e] - e
    elif e > d[e]:
        count +=  d[e]

print(count)

Solution (Python):
import collections

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


c = collections.Counter(a)


ans=0
for i in set(a):
  tmp=c[i]
  if tmp-i<0:
    ans+=tmp
  else:
    ans+=tmp-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 i in set(a):
  tmp=c[i]
  if tmp-i<0:
    ans+=tmp
  else:
    ans+=tmp-i
  
print(ans)

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

Solution (Python):
from collections import Counter

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

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

Solution (Python):
from collections import defaultdict
N = int(input())
A = map(int,input().split())
dic = defaultdict(int)
for a in A: dic[a] += 1

ans = 0
for k in dic.keys():
    n = dic[k]
    if n < k: ans += n
    elif k < n: ans += n-k

print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())
li_a = input().split()

ndict = defaultdict(int)

for i in li_a:
    ndict[i] += 1

result = 0
for k in ndict.keys():
    if ndict[k] > int(k):
        result += ndict[k] - int(k)
    elif ndict[k] < int(k):
        result += ndict[k]

print(result)

Solution (Python):
def main():
    N = int(input())
    cnt = {}
    for c in map(int, input().split()):
        if c not in cnt:
            cnt[c] = 0
        cnt[c] += 1
    ans = 0
    for k in cnt:
        if k <= cnt[k]:
            ans += cnt[k]-k
        else:
            ans += cnt[k]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import collections

n=int(input())

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

X=collections.Counter(A)
K=list(X.keys())
V=list(X.values())
cnt=0
for i in range(len(X)):
    if K[i]>V[i]:
        cnt+=V[i]
    elif K[i]<V[i]:
        cnt+=V[i]-K[i]

print(cnt)

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

Solution (Python):
N=int(input())
d={}
for i in map(int,input().split()):d[i]=d.get(i,0)+1
r=0
for k,v in d.items():r+=v if v<k else v-k
print(r)

Solution (Python):
from collections import Counter
N=int(input())
ans=0
a=list(map(int,input().split()))
d = Counter(a)
for k in d:
    val = d[k]
    if val>=k:
        ans+=val-k
    else:
        ans+=val
print(ans)

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

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

L = []
for i in dic.keys():
    if dic[i] >= i:
       L.append(dic[i]-i)
    else:
       L.append(dic[i])

print(sum(L))

Solution (Python):
import bisect

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

a.sort()
bp = bisect.bisect_right( a, 1e+5 )

ans = 0
ans += len( a[bp:] )

num = [0] * (100001)
for i in a[:bp]: num[i] += 1

for i in range(len(num)):
    if num[i] > i: ans += num[i] - i
    if num[i] < i: ans += num[i]

print( ans )

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
res = 0
for k, v in c.items():
    if v < k:
        res += v
    else:
        res += v-k
print(res)

Solution (Python):
from collections import Counter
N = int(input())
cnt = 0
for k, v in Counter([int(i) for i in input().split()]).items():
    if v > k:
        cnt += v - k
    elif v < k:
        cnt += v
print(cnt)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = list(set(A[:]))
count = 0

B = Counter(A).most_common()
for k, v in B:

    if k < v:
        count += v-k
    elif k > v:
        count += v
print(count)

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

A.sort()
B = []
B.append([A[0], 1])
for i in range(1, n) :
    if A[i] != A[i-1] :
        B.append([A[i], 1])
    else :
        B[-1][1] += 1


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

print(ans)

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
sA=set(A)
ans=0
d={}
for s in sA:
	d[s]=0
for a in A:
	d[a]+=1
for s in sA:
	if d[s]-s>=0:
		ans+=min(d[s],d[s]-s)
	else:
		ans+=d[s]
print(ans)

Solution (Python):
from collections import Counter

n=int(input())
l=list(map(int,input().split()))
a=Counter(l)
c=a.most_common()
m=len(c)
ans=0
for i in range(m):
  x=c[i][0]
  y=c[i][1]
  if x>y:
    ans+=y
  elif x<y:
    ans+=y-x
print(ans)

Solution (Python):

import copy
import numpy as np
import random
n = int(input())

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


count_dic = {}
for a in A:
    if a in count_dic:
        count_dic[a] += 1
    else:
        count_dic[a] = 1

ans = 0

for key in count_dic.keys():
    if count_dic[key] == key:
        pass
    elif count_dic[key]<key:
        ans += count_dic[key]
    else:
        ans += count_dic[key]-key
        count_dic[key] = key


print(ans)

Solution (Python):
import collections as c
a=c.Counter(list(map(int,open(0).read().split()[1:])))
print(sum([[v-k,v][k>v] for k,v in a.items()]))

Solution (Python):
from collections import Counter
input();a=Counter(list(map(int,input().split())))
print(sum([v if k>v else v-k for k,v in a.items()]))

Solution (Python):
n,*a=map(int,open(0).read().split())
d={}
for i in a:d[i]=d.get(i,0)+1
print(sum(d[i]-i*(d[i]>=i)for i in d))

Solution (Python):
n,*a=map(int,open(0).read().split());d={}
for i in a:d[i]=d.get(i,0)+1
print(sum(d[i]-i*(d[i]>=i)for i in d))

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
for k,v in d.items():
    if k <= v:
        n -= k
print(n)

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

d = {}
for a in A:
  if(a in d):
    d[a] += 1
  else:
    d[a] = 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
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = IL()
cl = collections.Counter(l)

key = list(cl.keys())
value = list(cl.values())

ans = 0
for i in range(len(key)):
	k = int(key[i])
	v = value[i]
	if k <= v:
		ans += v-k
	else:
		ans += v

print(ans)

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

res = 0

num = [0]*(N)
cnt = [0]*(N)

for i in range(N):
    if A[i] > N:
        res += 1
    else:
        cnt[A[i]-1] += 1

for i in range(N):
    if cnt[i] < i+1:
        res += cnt[i]
    else:
        res += cnt[i] - (i+1)

print(res)

Solution (Python):
from sys import stderr, setrecursionlimit
from collections import Counter
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = Counter(getints())
debug(a)
ans = 0

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

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(0)
ans = 0
k = L[0]
cnt = 0
for i in range(N+1):
  if k == L[i]:
    cnt += 1
  else:
    if cnt >= k:
      ans += cnt-k
    else:
      ans += cnt
    cnt = 1
    k = L[i]
print(ans)

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

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

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

Solution (Python):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=Counter(A)
ans=0
for i in C.keys():
    if i>C[i]:
        ans+=C[i]
    elif i<C[i]:
        ans+=C[i]-i
print(ans)

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

count = [0] * (10 ** 5 + 1)
ans = 0
for i in a:
    if i <= 10 ** 5:
        count[i] += 1
    else:
        ans += 1
for i,j in enumerate(count):
    if (j - i) >= 0:
        ans += j - i
    else:
        ans += j
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
A=Counter(list(map(int,input().split())))
ans=0
for i,j in A.items():
  if j-i<0:
    ans+=j
  else:
    ans+=min((j-i),j)
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):
    if(k > v):
      cnt += v
    else:
      cnt += v - k
print(cnt)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt = [0,] * 100001
for i in range(n):
    if a[i] > 100000:
        ans += 1
    else:
        cnt[a[i]] += 1
for i in range(100001):
    if cnt[i] > i:
        ans += cnt[i] - i
    elif cnt[i] < i:
        ans += cnt[i]
print(str(ans))

Solution (Python):
N = input()

data = map(int,raw_input().split())
data.sort()

count = []
num = []
pnum = -1
counter = -1

for i in data:
    if pnum != i:
        pnum = i
        num.append(i)
        count.append(1)
        counter += 1
    else:
        count[counter] += 1

ans = 0

for i in range(len(num)):
    if count[i] < num[i]:
        ans += count[i]
    else:
        ans += count[i]-num[i]

print ans

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

for k in c.keys():
    ans += c[k] if c[k] < k else c[k]-k
print(ans)

Solution (Python):
from collections import Counter


def solve(N, As):
    c = Counter(As)
    ans = 0
    for k, v in c.items():
        if k < v:
            ans += v - k
        elif k == v:
            pass
        else:
            ans += v
    return ans

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))