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 = list(map(int,input().split()))

c = Counter(a)
key = c.keys()
f = []
ans = 0

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

print(ans)

Solution (Python):
from collections import*
_, *a = map(int, open(0).read().split())
print(sum(v - i if i < v else v if i > v else 0 for i, v in Counter(a).items()))

Solution (Python):
import collections


def inputStrOnebyOne():
    s = list(input())
    return s


def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a

def main():
	n = input()
	a = list(map(int,input().split()))
	c = collections.Counter(a)
	cntRem = 0

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

if __name__=='__main__':
    main()

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

als.sort()

my_dict = dict()

for item in als:
    if item in my_dict:
        my_dict[item] += 1
    else:
        my_dict[item] = 1


ret = 0
for item in my_dict:
    val = my_dict[item]
    if val < item:
        ret += val
    else:
        ret += (val - item)

print(ret)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
ans = 0
c = Counter(a)
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(x) for x in input().split()]
c = Counter(a)
ans = 0
for v, c in c.items():
  if v < c:
    ans += c-v
  if v > c:
    ans += c

print(ans)

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

Solution (Python):
from collections import Counter

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

print(sum([count if number > count else count - number for number, count in counter.items()]))

Solution (Python):
from collections import Counter

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

ans = 0
for key, val in Counter(a).most_common():
    if key > val:
        ans += val
    elif key < val:
        ans += val - key

print(ans)

Solution (Python):

"""
Created on Thu May 14 11:47:51 2020

@author: shinba
"""

n = int(input())

data = {}
ans = 0

for x in map(int,input().split()):
    if not x in data:
        data[x] = 1
    else:
        if data[x] < x:
            data[x] += 1
        else:
            ans += 1

for i,j in data.items():
    if i == j:
        continue
    ans += j
    
print(ans)

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = collections.Counter(il())

    ret = 0
    for k in A:
        v = A[k]
        if k <= v:
            ret += abs(k-v)
        else:
            ret += v
    print(ret)


if __name__ == '__main__':
    main()

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

Solution (Python):
def myAnswer(N:int,A:list) -> int:
   dic = {}
   counter = 0
   for a in A:
      if(a in dic.keys()):
         if(dic[a]==a):
            counter += 1
         else:
            dic[a]+= 1
      else:
         dic[a] = 1
   for key,value in dic.items():
      if(value < key):
         counter += value
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Solution (Python):

import sys
from collections import Counter
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,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)
    

if __name__ == '__main__':
    main()

Solution (Python):
n = input()
m = map(int, input().split())
d = {}
for i in m:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
cnt = 0
for i in d.items():
    if i[0] > i[1]:
        cnt += i[1]
    elif i[0] < i[1]:
        cnt += i[1]-i[0]
print(cnt)

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

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

print(count)

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

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

v = list(l.keys())

ans = 0
for i in v:
    if (l.get(i)>=i):
        ans += (l.get(i)-i)
    else:
        ans += l.get(i)
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():
  tmp = v - k if k <= v else v
  ans += tmp
print(ans)

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
a_key = list(a.keys())
a_value = list(a.values())
cnt = 0
for i in range(len(a)):
    x = int(a_value[i])-int(a_key[i])
    if  x >= 0:
        cnt += x
    else:
        cnt += a_value[i]
print(cnt)

Solution (Python):
from collections import Counter

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

c = Counter(a)
cnt = 0
for key,value in Counter(a).items():
    if key < value:
        cnt += value - key
    if key > value:
        cnt += value
print(cnt)

Solution (Python):
A=int(input())
import collections
B=list(map(int,input().split()))
B=collections.Counter(B)
C=list(B.keys())
D=list(B.values())
ans = 0
for i,j in zip(C,D):
    if i > j:
        ans+=j
    elif i < j:
        ans+=j-i
print(ans)

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy





sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))




def main():
    n = ni()
    a = na()

    c = collections.Counter(a)

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy





sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))




def main():
    n = ni()
    a = na()

    c = collections.Counter(a)

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys, collections
n = int(input())
a = collections.Counter(sys.stdin.readline().split())
ans = 0
for i in a:
    if int(i) > a[i]:
        ans += a[i]
    elif int(i) < a[i]:
        ans += a[i] - int(i)
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
c = Counter(l)
ans = 0
for k,v in c.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()))

c = Counter(a)

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

print(ans)

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

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

def resolve():
	n = int(input())
	c = Counter(list(map(int, input().split())))
	lis = list(c.keys())
	ans = 0
	for k in c.keys():
		if k != c[k]:
			if k > c[k]:
				ans += c[k]
			else:
				ans += c[k] - k
	print(ans)
resolve()

Solution (Python):
from collections import Counter

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

a=Counter(a)
ans=0
for key,count in a.most_common():
    key=int(key)
    if count>=key:
        ans+=count-key
    else:
        ans+=count
print(ans)

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

li.sort()
ans = 0
cnt = 0
check = 0

for i in li:
    if i != check:
        if cnt >= check:
            ans += cnt - check
        else:
            ans += cnt

        check = i
        cnt = 1
    else:
        cnt += 1
else:
    if cnt >= check:
        ans += cnt - check
    else:
        ans += cnt

print(ans)

Solution (Python):
from collections import Counter

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

counts = Counter(a_s)

ans = 0
for key in counts.keys():
    if key <= counts[key]:
        ans += counts[key] - key
    else:
        ans += counts[key]
        
print(ans)

Solution (Python):
import collections
import fractions
from functools import reduce
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = input_list()
    ac = collections.Counter(a)
    
    ans = 0
    for num, count in ac.items():
        if num < count:
            ans += count - num
        if num > count:
            ans += count
    print(ans)

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if __name__ == "__main__":
    main()

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

ans=0
import collections
c=collections.Counter(a)
c=c.most_common()
for i in range(len(c)):
    x=c[i][0]
    y=c[i][1]
    if x<=y:
        ans += y-x
    else:
        ans += y
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
ac = Counter(a)
an = len(ac)
a_mostcommon = ac.most_common()
cnt = 0
for i in range(an):
  num, count = a_mostcommon[i]
  if count > num:
    cnt += count - num
  elif count < num:
    cnt += count

print(cnt)

Solution (Python):
ma = lambda :map(int,input().split())
n = int(input())
A = list(ma())
import collections
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num>cnt:ans+=cnt
    if num<cnt:ans+=(cnt-num)
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n, *a = map(int, read().split())
ans = 0
for k, v in Counter(a).items():
    if k > v:
       ans += v
    elif k < v:
        ans += v - k
print(ans)

Solution (Python):
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    count = Counter(A)
    ans = 0
    for key, value in count.items():
        if key == value:
            continue
        else:
            if key<value:
                ans += value-key
            else:
                ans += value
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque,Counter

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

cnt = Counter(lisA)

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

print(ans)

Solution (Python):
import collections

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

c = collections.Counter(a)
cnt=0

for item in c.keys():
    if c[item]>=item:
        cnt+=c[item]-item
    else:
        cnt+=c[item]
print(cnt)

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    A_list = [int(item) for item in input().split()]

    cnt_dict = collections.Counter(A_list)

    cnt = 0
    for i, v in cnt_dict.items():
        if i <= v:
            cnt += v - i
        elif i > v:
            cnt += v
    print(cnt)
if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import Counter


n = int(input())
m = Counter(map(int, input().split()))
ans = 0
for i, j in m.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 = list(map(int, input().split()))

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

print(count)

Solution (Python):
from collections import Counter

N = int(input())

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

x = set(a)


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


print(res)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    d=dict()
    for i in range(n):
        if a[i] not in d:
            d[a[i]]=1
        else:
            d[a[i]]+=1

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

    print(res)

if __name__=="__main__":
    main()

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

Solution (Python):
import collections
n=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
r=0
for x in c:
    if x<c[x]:r+=c[x]-x
    if x>c[x]:r+=c[x]
print(r)

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

di = {}
for i in a:
    if i in di:
        di[i] += 1
    else:
        di[i] = 1

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

Solution (Python):
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    pair = defaultdict(int)

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

    cnt = 0
    for num, count in pair.items():
        if count >= num:
            cnt += count - num
        else:
            cnt += count

    print(cnt)
if __name__ == "__main__":
    main()

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

dic={}
for i in li:
    if i not in dic:
        dic[i] = 1
    elif dic[i] >= 1:
        dic[i] += 1
        

cnt = 0
for i in dic:
    
    
    if i>dic[i]:
        cnt += dic[i]
    else:
        cnt += dic[i]-i
print(cnt)

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

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 k > v:
        ans += v
    elif k < v:
        ans += v-k
print(ans)

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

import collections
c=collections.Counter(a)



cnt=0
for i in c.most_common():
   
    if i[0]<i[1]:
      cnt=cnt+i[1]-i[0]
    if i[0]>i[1]:
      cnt=cnt+i[1]
print(cnt)

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

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

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X = ii()
    A = collections.Counter(il())

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


if __name__ == '__main__':
    main()

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 v > k:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

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
d=list(d.items())
cnt=0
for i in range(len(d)):
  if d[i][0]>d[i][1]:
    cnt+=d[i][1]
  elif d[i][0]<d[i][1]:
    cnt+=(d[i][1]-d[i][0])
print(cnt)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
count=0
lcount=[0]*(10**5+1)
for i in l:
    if i>10**5:
        count+=1
    else:
        lcount[i]+=1
        if lcount[i]>i:
            count+=1
for j in l:
    if j<=10**5 and lcount[j]<j:
        count+=1
print(count)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
item = []
for key,value in c.items():
    item.append([key,value])
cnt = 0
for i in range(len(item)):
    if item[i][0] == item[i][1]:
        continue
    elif item[i][0] < item[i][1]:
        cnt += item[i][1] - item[i][0]
    else:
        cnt += item[i][1]
print(cnt)

Solution (Python):
from collections import Counter

N = int(input())
c = Counter(int(x) for x in input().split())

answer = 0

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

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

c = collections.Counter(li)






if len(li) == 0:
    print(0)
    exit()

count = 0
for ci in c.items():
    a = ci[0]
    b = ci[1]
    if a<b:
        count += b-a
    elif a>b:
        count += b
print(count)

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

answer = 0
C = Counter (A)
C_taple = C.most_common()
for c in C_taple:
    if c[0] > c[1]:
        answer += c[1]
    elif c[1] > c[0]:
        answer += (c[1]-c[0])
print(answer)

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

dic = dict()

for a in A:
    if str(a) in dic:
        dic[str(a)] += 1
    else:
        dic[str(a)] = 1

res = 0
for i, cnt in dic.items():
    ii = int(i)
    if ii < cnt:
        res += cnt - ii
    elif ii > cnt:
        res += cnt

print(res)

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

dic = dict()

for a in A:
    if str(a) in dic:
        dic[str(a)] += 1
    else:
        dic[str(a)] = 1

res = 0
for i, cnt in dic.items():
    ii = int(i)
    if ii < cnt:
        res += cnt - ii
    elif ii > cnt:
        res += cnt

print(res)

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

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

Solution (Python):
from collections import Counter


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

ans = 0

for a, b in list(S.items()):
    if a < b:
        ans += b - a
    elif a > b:
        ans += b

print(ans)

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

a = Counter(a)
key = a.keys()
ans = 0
for i in key:
    if a[i] > i:
        ans += a[i] - i
    elif a[i] < i:
        ans += a[i]
print(ans)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

INIT_VAL = 0
def DD2(d1,d2): return [[INIT_VAL]*d2 for _ in range(d1)]
def DD3(d1,d2,d3): return [DD2(d2,d3) for _ in range(d1)]

MOD=10**9+7
def divc(x,y): return -(-x//y)
def divf(x,y): return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers"""
    is_prime = [True] * MAX_NUM
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(MAX_NUM):
        if is_prime[i]:
            primes.append(i)
            for j in range(2*i, MAX_NUM, i):
                is_prime[j] = False
    return primes

from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left



def main():
    n = II()
    aa = MII()
    c = Counter(aa)
    keys = sorted(c.keys())
    cnt = 0
    for k in keys:
        if c[k] > k:
            cnt += c[k] - k
        elif c[k] < k:
            cnt += c[k]
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
cnt = 0
d = {}
a_list = list(map(int,input().split()))
for i in a_list:
    d.setdefault(i,1)
    d[i] += 1
for i in d:
    if d[i]-1 >= i:
        cnt += abs(d[i]-1-i)
    else:
        cnt += d[i]-1
        
print(cnt)

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

num_dict = dict()
for a_i in a:
    if a_i in num_dict:
        num_dict[a_i] += 1
        continue
    num_dict[a_i] = 1

ans = 0
for num in num_dict:
    if num_dict[num] == num:
        continue
    if num_dict[num] < num:
        ans += num_dict[num]
        continue
    ans += num_dict[num]-num

print(ans)

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

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

ans = 0
for x,y in a.items():
    if x == y: continue
    if x < y: ans += y-x
    else: ans += y
print(ans)

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

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

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

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
c = 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_ls = list(map(int, input().split()))
c = Counter(a_ls)

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

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

d=dict()

for i in range(n):
    if a[i] in d:
        d[a[i]]=d[a[i]]+1
    else:
        d[a[i]]=1
        
xsum=0
for x in d.keys():
    if d[x]<x:
        xsum=xsum+d[x]
    elif d[x]>x:
        xsum=xsum+d[x]-x
        
print(xsum)

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

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

print(ans)

Solution (Python):
from collections import defaultdict

N = int(input())
if not N == 1:
    counter = defaultdict(lambda: 0)
    for e in list(map(int, input().split())):
        counter[e] += 1
    answer = 0
    for i in counter:
        ball_count = counter[i]
        if not i == ball_count:
            if i > ball_count:
                answer += ball_count
            elif i < ball_count:
                answer += ball_count - i
    print(answer)
else:
    if not 1 == int(input()):
        print(1)
    else:
        print(0)

Solution (Python):
from collections import defaultdict

N = int(input())
if not N == 1:
    counter = defaultdict(lambda: 0)
    for e in list(map(int, input().split())):
        counter[e] += 1
    answer = 0
    for i in counter:
        ball_count = counter[i]
        if i > ball_count:
            answer += ball_count
        elif i < ball_count:
            answer += ball_count - i
    print(answer)
else:
    if not 1 == int(input()):
        print(1)
    else:
        print(0)

Solution (Python):
import collections
import sys
sys.setrecursionlimit(2000000)




n = int(input())

a = list(map(int, input().split()))
a_count = collections.Counter(a)
a_list = list(a_count.items())
a_sorted = sorted(a_list, key=lambda x: x[1])

count = 0
for i in range(len(a_sorted)):
    if a_sorted[i][0] != a_sorted[i][1]:
        if a_sorted[i][0] < a_sorted[i][1]:
            count += a_sorted[i][1]-a_sorted[i][0]
        else:
            count += a_sorted[i][1]

print(count)

Solution (Python):
def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
n=int(input())
a=list(map(int,input().split()))
d=dict()
for i in a:
    d=mycounter(d,i)
p=0
for i,j in d.items():
    if i<j:
        p+=j-i
    if i>j:
        p+=j
print(p)

Solution (Python):
from collections import defaultdict

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

adic=defaultdict(int)
for a in alist:
  adic[a]+=1


answer=0
for key in adic:
  if adic[key]<key:
    answer+=adic[key]
  else:
    answer+=adic[key]-key
    
print(answer)

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

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

Solution (Python):
from collections import Counter
N = int(input())
an = list(map(int, input().split()))
counts = Counter(an).items()
ans = 0
for count in counts:
    if count[0] > count[1]:
        ans += count[1]
    else:
        ans += count[1] - count[0]
print(ans)

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    ans = 0
    for k, v in zip(c.keys(), c.values()):
        if v - k >= 0:
            ans += v - k
        else:
            ans += v
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a_dic = {}
for i in range(n):
    if a[i] not in a_dic:
        a_dic[a[i]] = 0
    a_dic[a[i]] += 1
a_key = list(a_dic.keys())
a_val = list(a_dic.values())

ans = 0

for i in range(len(a_key)):
    if a_key[i] > a_val[i]:
        ans += a_val[i]
    else:
        ans += a_val[i] - a_key[i]

print(ans)