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):
n = int(input())
a = list(map(int,input().split()))
b = {}
for i in a:
    b[i] = b.get(i,0)+1
s =0
for i in b.keys():
    c = b[i]
    if(c<i):
        s += c
    elif(c>i):
        s += c-i
print(s)

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

for i in a:
    m[i] = m.get(i, 0) + 1

result = 0
for i in m.keys():
    v = m.get(i, 0)
    if v >= i:
        result += v - i
    else:
        result += v
print(result)

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

count=1
ans=0

for i in range(0,n):
    if a[i+1]==a[i]:
        count += 1
    else:

        if count > a[i]:
            ans += count - a[i]
        elif count < a[i]:
            ans += count

        count = 1

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
set_a=set(a)
import collections
count=0
data=collections.Counter(a)
for i,j in data.items():
    if i<j:
        count+=j-i
    elif j<i:
        count+=j
print(count)

Solution (Python):
import collections
A=int(input())
N=list(map(int,input().split()))
dic=dict(collections.Counter(N))
cnt=0

for i,j in dic.items():
    tmp=j-i
    if i>j:
        cnt+=j
    elif i<j:
        cnt+=j-i
print(cnt)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
dlt=0
push=0
a.sort()
k=0
while(1):
  i=a[k+push]
  if(i>n):
    dlt+=1
    push+=1
  else:
    j=a.count(i)
    push+=j
    if(j>i):dlt+=j-i
    elif(i>j):dlt+=j
  if(k+push>=n):break
print(dlt)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
count_delete = 0
count_dict = collections.Counter(a)
for k, v in count_dict.items():
    if k != v:
        if k > v:
            count_delete += v
        else:
            count_delete += min(v-k, v)
print(count_delete)

Solution (Python):



import sys

def main():
    n = int(sys.stdin.readline())
    a = map(int, sys.stdin.readline().split())

    d = {}
    for e in a:
        if e not in d:
            d[e] = 1
        else:
            d[e] += 1

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

    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
def C_Good_Sequence():
    N=int(input())
    a=list(map(int, input().split()))
    count={}
    ans=0
    
    for num in a:
        count[num]= count.get(num,0)+1

    for num in count:
        if num > count[num]:
            ans += count[num]
        elif num < count[num]:
            ans += count[num]-num
    
    print(ans)
   
C_Good_Sequence()

Solution (Python):
def main():
    x = int(input())

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

    B = {}
    count = 1
    a = -1
    for i in A:
        if a == i:
            count += 1
        elif a >= 0:
            B.update({a:count})
            count = 1

        a = i

    B.update({a:count}) 

    count = 0
    for key in B.keys():
        val = B.get(key)
        diff = val - key

        if diff >= 0:
            count += diff
        else:
            count += val

    print (count)


if __name__ == "__main__":
    
    
    main()

Solution (Python):



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

n_rmv = 0
A.sort()
A.append(0)

i = 0
while i < len(A):
    if A[i] == 0: break
    try:
        tmp = A[i]
        if A[i+A[i]-1] != A[i]:
            while tmp == A[i]:
                n_rmv += 1
                i += 1
        else:
            i += A[i]
            while tmp == A[i]:
                n_rmv += 1
                i += 1
    except IndexError:
        n_rmv += len(A[i:-1])
        break
print(n_rmv)

Solution (Python):
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    D = defaultdict(lambda: 0)

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

    r = 0
    for k,v in D.items():
        if k < v:
            r += v - k
        elif k > v:
            r += v

    print(r)

main()

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

Solution (Python):
N = int(input())
a = map(int,input().split())
dic={}

ans=0
for i in a:
	dic.setdefault(i,0)
	dic[i]+=1
for a,b in dic.items():	
	if b-a>=0:
		ans += b-a
	else:
		ans += b
print(ans)

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

Solution (Python):
from collections import Counter

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

count=Counter(a)
outrange=0
flow=0

for i in range(n):
    if (a[i]>n):
        outrange+=1

for i in range(1,n+1):
    if (count[i]>i):
        flow+=count[i]-i
    elif (count[i]<i):
        flow+=count[i]

print(flow+outrange)

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

dic = {}
for num in l:
    dic.setdefault(num, 0)
    dic[num]+=1

result = 0
for k, v in dic.items():
    if k > v:
        result = result + v
    elif k < v:
        result += (v - k)

print(result)

Solution (Python):


import sys

n = int(raw_input().split()[0])
a = [int(e) for e in raw_input().split()]
d = dict()



for ai in a:
    d[ai] = d.get(ai, 0) + 1

n = 0
for k, v in d.iteritems():
    if k > v:
        n += v
    elif v > k:
        n += (v - k)
        
sys.stdout.write('%d\n' % n)
sys.stdout.flush()

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


c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

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


c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    total = 0
    for i, a in enumerate(A):
        b = B.get(a, 0)
        if b == 0:
            B[a] = 1
        else:
            B[a] += 1

    for i in B:
        if B[i] == 0:
            continue
        if B[i] == i:
            continue
        elif B[i] > i:
            total += B[i] - i
        else:
            total += B[i]
    print(total)
main()

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

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

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

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

Solution (Python):
from collections import Counter

N = int(input())
counter = Counter(map(int, input().split()))

sum = 0

for a, cnt in counter.items():
    if a > cnt:
        sum += cnt
    else:
        sum += cnt - a

print(sum)

Solution (Python):
from collections import Counter

N = int(input())
counter = Counter(map(int, input().split()))

sum = 0

for a, cnt in counter.most_common():
    if a > cnt:
        sum += cnt
    else:
        sum += cnt - a

print(sum)

Solution (Python):
num = int(input())
num_dict = {}
nums = [int(i) for i in input().split()]
count = 0

for i in range(num):
    if nums[i] in num_dict.keys():
        num_dict[nums[i]] += 1
    else:
        num_dict[nums[i]] = 1

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

print(count)

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_a

"""
import sys
from sys import stdin
from collections import Counter
input = stdin.readline


def solve(A):
    ans = 0
    for v, f in Counter(A).most_common():
        if v > f:
            ans += f
        elif f > v:
            ans += (f - v)
    return ans


def main(args):
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = solve(A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
from collections import Counter
n=int(input())
counter=Counter(map(int,input().split()))
print(sum(c-num if c>=num else c for num,c in counter.items()))

Solution (Python):
from collections import Counter
N = int(input())
cnt = Counter(map(int, input().split()))
print(sum(v - k if v >= k else v for k, v in cnt.items()))

Solution (Python):
from collections import Counter

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

ans = 0
counter = Counter(A)
for i, c in counter.most_common():
    if c < i:
        ans += c
    else:
        ans += c - i
print(ans)

Solution (Python):
from collections import defaultdict
d = defaultdict(lambda: 0)
N = int(input())
a = list(map(int, input().split()))
for tmp_a in a:
    d[tmp_a] += 1
key_list = list(d.keys())
key_list.sort()
counter = 0
for key in key_list:
    if d[key]>=key:
        counter += d[key]-key
    else:
        counter += d[key]

print(counter)

Solution (Python):
N=int(input())
l=input().split(' ')
l.sort()
count=0
i=0
while i <len(l):
    p=1
    while p < int(l[i]):
        if p+i == len(l):
            del l[i:i+p]
            count+=p
            p=0
            break
        elif l[i]!=l[i+p]:
            del l[i:i+p]
            count += p
            p=0
            break
        else:
            p+=1
    if p != 0:
        while i+p < N:
            if l[i] == l[i+p]:
                p+=1
            else:
                break
        del l[i+int(l[i]):i+p]
        count += p-int(l[i])
        i += int(l[i])
print(count)

Solution (Python):
n = int(input())
a = []
a =  list(map(int, input().split()))
d = {}
c = 0
for x in a:
    d[x] = d.get(x, 0) + 1
for y,z in d.items():
    if y < z:
        c += z-y
    if y > z:
        c += z
print(c)

Solution (Python):
from collections import Counter
N=int(input())

s=input().split()
c=Counter(s)
count=0
for i in c:
    if int(i)>c[str(i)]:
        count+=int(c[str(i)])
    elif int(i)<c[str(i)]:
        count+=int(c[str(i)])-int(i)
    else:
        continue
print(count)

Solution (Python):
def foo(xs):
    d = {}
    for x in xs:
        d[x] = d.get(x, 0) + 1
    
    count = 0
    for k, v in d.items():
        if k > v:
            count += v
        elif k < v:
            count += (v - k)
        elif k == v:
            pass
        else:
            pass
    return count



if __name__ == "__main__":
    n = input()
    xs = map(int, input().split())
    print(foo(xs))

Solution (Python):
N = input()
a = map(int, raw_input().split())
numbers = {}
for i in range(N):
    numbers[a[i]] = numbers.get(a[i], 0) + 1
ans = 0
for k, v in numbers.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()))
dic = {}
for elem in a:
    if elem not in dic:
        dic[elem] = 1
    else:
        dic[elem] += 1

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

print(ans)

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

a.sort()
a.append(0)

T=[]
j=0
t=0
s=0
for i in range(N):
    j+=1
    if a[i] != a[i+1]:
        if j-s > a[i]:
            t+=(j-s)-a[i]
        elif j-s < a[i]:
            t += j-s
        s=j

print(t)

Solution (Python):
import math

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


def f7(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if x not in seen and not seen_add(x)]

d = 0

a_unique = {}

for i in range(0,len(a)):
    if a[i] in a_unique:
        a_unique[a[i]] += 1
    else:
        a_unique[a[i]] = 1

for ai in a_unique.keys():
    if a_unique[ai] >= ai:
        d += a_unique[ai] - ai
    else:
        d += a_unique[ai]

print(d)

Solution (Python):
from collections import Counter

ignore = int(raw_input())
k = dict(Counter(map(int, raw_input().split())))
copyk = list(set(k))
counter = 0
for i,j in k.items():
    if i > j:
        counter += j
    elif i < j:
        counter += j - i

print counter

Solution (Python):
from collections import Counter

ignore = int(raw_input())
k = dict(Counter(map(int, raw_input().split())))
copyk = list(set(k))
counter = 0
for i,j in k.items():
    if i > j:
        counter += j
    elif i < j:
        counter += j - i

print counter

Solution (Python):
from collections import Counter

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

C = dict(Counter(a))

ans = 0
for num, kosu in C.items():
    if num > kosu:
        ans += kosu
    else:
        ans += kosu - num
print(ans)

Solution (Python):
N=int(input())
cnt=[int(i) for i in input().split()]
dict={}
for i in range(len(cnt)):
  if cnt[i] in dict:
    dict[cnt[i]]+=1
  else:
    dict[cnt[i]]=1

ans=0
for j,k in dict.items():
  if int(j)>k:
    ans+=k
  else:
    ans+=k-int(j)
print(ans)

Solution (Python):

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

dic = {}
for elem in a:
    if elem not in dic:
        dic[elem] = 1
    else:
        dic[elem] += 1

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

print(cnt)

Solution (Python):



n = int(input())
xs = map(int, input().split())

mp = dict()

for x in xs:
    if x in mp:
        mp[x] = mp[x] + 1
    else:
        mp[x] = 1

res = 0
for x in mp.keys():
    v = mp[x]
    if v < x:
        res += v
    else:
        res += v - x

print(res)

Solution (Python):



from collections import Counter

N = int(raw_input())
a = map(int, raw_input().split())
result = 0
cnt = Counter()

for num in a: cnt[num] += 1

for x, y in cnt.items():
  result += y if x>y else y-x

print result

Solution (Python):
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque








def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)


def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))





def main():
	n = I()
	A = LI()
	d=defaultdict(lambda: 0)
	for a in A:
		d[a] += 1
	ans=0
	for k,v in d.items():
		if k>v:
			ans+=v
		else:
			ans += v-k

	print(ans)




if __name__ == '__main__':
	main()

Solution (Python):
from collections import defaultdict

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

d=defaultdict(int)
for b in a:
    d[b] +=1

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

print(c)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
i = 0
a = sorted(a)
b = []
num = 0
ins = 1
while i < len(a):
    while ins == a[i]:
        num += 1
        if ins == num:
            b.append(ins)
        i += 1
        if len(a) == i:
            break
    if len(a) != i:
        ins = a[i]
    i += 1
    num = 1
print(len(a)-sum(b))

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

answer=0
count_sum=0

counter = Counter(a)
for num, cnt in counter.most_common():

  count_sum+=cnt
  if cnt>num:
    answer += cnt-num
  elif cnt<num:
    answer += cnt
answer+=N-count_sum
print(answer)

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

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

place = {}
counter = 0

for i in series:
    if i not in place:
        place[i] = 0
    place[i] += 1
    
for j in place.keys():
    if place[j] > j:
        counter += place[j] - j
    elif j > place[j]:
        counter += place[j]
        
print(counter)

Solution (Python):



import collections
import sys

n = sys.stdin.readline().strip()
a = sys.stdin.readline().strip().split(" ")
a_count = collections.Counter(a)
ans = 0
for k, v in a_count.items():
    if int(k) > v:
        ans += v
    else:
        ans += v - int(k)
print(ans)

Solution (Python):

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

Solution (Python):
N = int(input())
a = input().split()
list_a = list(a)
d = dict()
for i in range(len(list_a)):
    d[list_a[i]] = 0

for i in range(len(list_a)):
    d[list_a[i]] += 1

sum = 0
for item in d:
    key = int(item)
    val = d[item]
    if key > val:
        sum += val
    elif key < val:
        sum += val - key

print(sum)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
ans = 0
while i < n:
    head = a[i]
    if head + i - 1 >= n:
        ans += n - i
        break
    if a[head+i-1] != a[i]:
        while i < n and head == a[i]:
            i += 1
            ans += 1
    else:
        i += head
        while i < n and head == a[i]:
            i += 1
            ans += 1

print(ans)

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

def count(num, counter_list):
    if len(counter_list) == 0:
        counter_list.append([num, 0])
    current = counter_list[-1]     
    if current[0] == num:
        current[1] += 1
    else:
        counter_list.append([num, 1])

def calc(list):
    result = 0
    for item in list:
        cmp_count = item[1] - item[0]
        result += cmp_count if cmp_count >= 0 else item[1]
    return result

def main():
    A.sort()
    counter_list = []
    for i in range(N):
        count(A[i], counter_list)
    ans = calc(counter_list)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

N = int(input())

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

counter = Counter(numList)

ans = 0

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

print(ans)

Solution (Python):
from collections import Counter

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

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

    print(ans)

if __name__ == '__main__':
    main()

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

n_dic = {str(i):0 for i in set(numbers)}


for i in numbers:
    n_dic[str(i)] += 1
  
count = 0

for i,j in n_dic.items():
    if int(i) < j:
        count += j - int(i)
    
    elif int(i) > j:
        count += j
        
print(count)

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

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

d = defaultdict(int)
for a in A:
    d[a] += 1

ans = 0
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 = input()
counts = Counter(map(int, input().split()))

removes = 0
for num, occr in counts.items():
    if num > occr:
        removes += occr
    elif num < occr:
        removes += occr-num

print(removes)

Solution (Python):
N = int(input())
alist = input().split()
count = [0 for i in range(100001)]
for a in alist:
	a = int(a)
	if a<100001:
		count[a]+=1
good = 0
for i in range(100001):
	if count[i] >= i:
		good += i
print(N-good)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ans = 0
dic = {}

for i in range(N):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

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

print(ans)

Solution (Python):

import math

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

d = {}
for a in an:
    d[a] = d.get(a, 0) + 1

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

print(count)

Solution (Python):
from collections import Counter

_ = int(input())
nl = list(map(int, input().split()))

cnt = Counter(nl)

ans = 0
for w, c in cnt.most_common():
    if w > c:
        ans += c
    elif w < c:
        ans += c - w

print(ans)

Solution (Python):
from collections import defaultdict


def main():
    _ = input()
    
    n_dic = defaultdict(lambda: 0)
    for x in input().split():
        n_dic[int(x)] += 1

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


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = input()
a = list(map(int, input().split()))
c = list(set(a))
b = Counter(a)
ans = 0
for i, l in b.most_common():
    if i > l:
        ans += l
    elif i < l:
        ans += l - i
print(ans)

Solution (Python):
input()
d={}
for a in input().split():
    if a in d:
        d[a]+=1
    else:
        d[a]=1
print(sum([y if int(x)>y else y-int(x) if int(x)<y else 0 for x,y in d.items()]))

Solution (Python):


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


numbers_count = {}

for i in numbers:
    numbers_count[i] = 0 


for i in a:
    numbers_count[i] += 1


remove=0
for i in numbers:
    
    if(i > numbers_count[i]):
        remove += numbers_count[i]
    
    elif(i < numbers_count[i]):
        remove += numbers_count[i] - i

print(remove)

Solution (Python):
from collections import Counter

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

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

print(ans)

Solution (Python):

from collections import Counter

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

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

dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

for key, value in dic.items():
    if key-value > 0:
        ans += value
    else:
        ans += value-key

print(ans)

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

dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

for key, value in dic.items():
    if key-value > 0:
        ans += value
    else:
        ans += value-key

print(ans)

Solution (Python):
N=input()
A=input().split(' ')
dict={}
for i in A:
    if i not in dict.keys():
        dict[i]=1
    else:
        dict[i]+=1
count=0
for k,v in dict.items():
    k=int(k)
    v=int(v)
    if v<k:
        count+=v
    else:
        count+=v-k
print(count)

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

d = {}

ans=0

for i in range(N):
    if a[i] in d.keys():
        d[a[i]]+=1
        ans+=1
        if d[a[i]] == a[i]:
            ans-=a[i]
    else:
        d[a[i]] = 1
        ans+=1
        if a[i] == 1:
            ans-=1
print(ans)

Solution (Python):

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0
for tmp in list(set(a)):
    if b[tmp] > tmp:
        ans += b[tmp]-tmp
    elif b[tmp] < tmp:
        ans += b[tmp]
    else:
        continue
else:
    print(ans)

Solution (Python):

"""
Created on Tue Dec 19 16:13:34 2017

@author: kotania
"""
 
from collections import Counter

N = int(input())
aList = input().split()

aList.sort()

countDict = Counter(aList)

delsum = 0    

for k,v in countDict.items():
    if int(k) < v:
        delsum += v - int(k)
    elif int(k) > v:
        delsum += v

print (delsum)

Solution (Python):
def main():
    N = int(input())
    l = list(map(int,input().split(" ")))
    dic = {}
    count = 0
    for i in l:
        try:
            dic[i] += 1
        except Exception:
            dic[i] = 1

    for j in dic.items():
        count += j[1] - j[0] if j[1] >= j[0] else j[1]
    print(count)


if __name__=="__main__":
    main()

Solution (Python):
from collections import Counter
N = raw_input()
A = raw_input().split()

cnt = Counter()
for num in A:
    cnt[str(num)] += 1

answer = 0
for x, y in cnt.items():
    x = int(x)
    if x < y:
        answer += (y-x)
    elif x > y:
        answer += y
print answer

Solution (Python):
N = int(input())
list = [int(a) for a in input().split()]
dict = dict()
for i in range(N):
    if list[i] in dict:
        dict[list[i]] += 1
    else:
        dict[list[i]] = 1
count = 0
for i, j in dict.items():

    if i <= j:
        count += j - i
    else:
        count += j
              
print(count)

Solution (Python):

import collections

n=int(raw_input())
s=map(int,raw_input().split())
cnt=collections.Counter(s)
temp=0
for k,v in cnt.items():
 if k<=v:
  temp+=k
print len(s)-temp

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

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

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

Solution (Python):
n = input()
str = input()
nums = str.split()
num_dict = {}
for num in nums:
    if num in num_dict:
        num_dict[num] += 1
    else:
        num_dict[num] = 1
result = 0
for k, v in num_dict.items():
    if int(k) > v:
        result += v
    elif int(k) < v:
        result += (v - int(k))

print(result)

Solution (Python):


from collections import defaultdict

N = int(raw_input())
As = map(int, raw_input().split())

dic = defaultdict(lambda:0)
for a in As:
    dic[a] += 1

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

print count

Solution (Python):
N = input()
a = list(map(int, input().split()))
dict = {}
count = 0

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

for i in dict.keys():
    if dict[i] < i:
        count += dict[i]
    else:
        count += dict[i] - i

print(count)

Solution (Python):
import numpy as np
from collections import Counter
import collections
a = list(map(int,input().split()))
b = list(map(int,input().split()))

b = sorted(b)
l = Counter(b)
Num = 0
for k,v in l.items():
  if v-k>=0 :
  	Num += v-k
  else:
    Num += v 
print(Num)

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

res = 0
counter = Counter(a)
for i in set(a):
	if counter[i] < i:
		res += counter[i]
	else:
		res += counter[i] - i

print(res)

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

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

res = 0
for key, value in cnt.items():
	if key < value:
		res += value - key
	elif key > value:
		res += value

print(res)

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

Solution (Python):
n = int(input())
a = input().split(" ")

dicta = {'0':0}

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

ke = list(dicta.keys())
va = list(dicta.values())
ans = 0


for i in range(len(ke)):
    if int(ke[i])>va[i]:
        ans+= va[i]
    else :
        ans += va[i]-int(ke[i])

print(ans)

Solution (Python):


def main():
    n = int(raw_input())
    a_list = map(int, raw_input().split())

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

if __name__=="__main__":
    main()

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

N = int(input())
a = sorted(list(map(int, input().split())))
a.append(-1)

ans = 0
pre = 0
count = 0
for n in a:
    if n == pre or pre == 0:
        count += 1
    else:
        if count >= pre:
            ans += count - pre
        else:
            ans += count
        count = 1
    pre = n
print(ans)

Solution (Python):
inputs = int(input())
line = raw_input().split()

nums = [int(i) for i in line]

map_ = {}

for num in nums:
    if num not in map_:
        map_[num] = 0
    map_[num] += 1

count = 0
for key, item, in map_.iteritems():
    if item < key:
        count += item
    else:
        count += (item - key)

print count