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())
l = map(int,input().split())
d = {}
ans = 0
for i in l:
  if i not in d:
    d[i] = 1
  else:
    d[i] += 1
for k,v in d.items():
  if k != v:
    if k < v:
      ans += v - k
    else:
      ans += v
print(ans)

Solution (Python):

import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = [int(i) for i in input().split()]
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

ans = 0

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

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 = int(readline())
a = tuple(map(int, readline().split()))
memo = tuple(Counter(a).items())
ans = 0
for x, y in memo:
    if x <= y:
        ans += y - x
    else:
        ans += y
print(ans)

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

ans=0
for key in dic.keys():
    if dic[key]>=key:
        ans+=dic[key]-key
    else:
        ans+=dic[key]

print(ans)

Solution (Python):
N = int(input())
a = input().split()
ans = 0

from collections import Counter
d = Counter(a)

for i in d:
    if d[i] != int(i):
        if d[i] > int(i):
            ans += d[i] - int(i)
        else:
            ans += d[i]

print(ans)

Solution (Python):
N = int(input())
a = input().split()
d = {}
ans = 0

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

for i in d:
    if d[i] != int(i):
        if d[i] > int(i):
            ans += d[i] - int(i)
        else:
            ans += d[i]

print(ans)

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

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

import collections

C = collections.Counter(A)
t = 0
for i in C:
    if C[i] >= i:
        t += C[i] - i
    else:
        t += C[i]
print(t)

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

import collections

c=collections.Counter(a)


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

Solution (Python):
def main():
    from collections import Counter
    n = int(input())
    a = list(map(int, input().split()))
    b = Counter(a)
    ans = 0
    for k, v in b.items():
        if k == v:
            continue
        if k > v:
            ans += v
        else:
            ans += v - k

    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
for a in As:
    d[a] += 1
cnt = 0
for k in d.keys():
    if d[k]-k >= 0:
        cnt += d[k] - k
    else:
        cnt += d[k]
print(cnt)

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
A = Counter(A)
keys = list(A.keys())
count = 0
for i in range(len(A)):
    if keys[i]!=A[keys[i]]:
        if keys[i]>A[keys[i]]:
            count += A[keys[i]]
        else:
            count += A[keys[i]]-keys[i]
print(count)

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

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

c = dict(Counter(a))

cnt = 0

for i, j in c.items():
    if i > j: cnt += j
    else: cnt += j - i
print(cnt)

Solution (Python):
from collections import Counter, deque






import sys
sys.setrecursionlimit(10 ** 5 + 10)


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

    AA=Counter(A)
    ans=0
    for k,v in AA.items():
        if v-k>=0:
            ans+=v-k
        else:
            ans+=v
    print(ans)
resolve()

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

N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for i,v in c.items():
    if v > i:
        ans += v-i
    elif v < i:
        ans += v
print(ans)

Solution (Python):


from collections import Counter


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

    result = 0
    for key, value in Counter(A).items():
        if value > key:
            result += (value - key)
        elif value < key:
            result += value

    print(result)


if __name__ == "__main__":
    main()

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

Solution (Python):
from collections import Counter
n,*a=map(int,open(0).read().split())
c=Counter(a)
ans=0
for i in c.keys():
  ans+=c[i]-[i,0][c[i]-i<0]
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():
    k = int(k)
    
    if k<v:
        ans += (v-k)
    elif k>v:
        ans += v

print(ans)

Solution (Python):
from collections import Counter


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

C = Counter(A)

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

print(cnt)

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

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

ans = 0
cnt = 1

if n ==1:
    if a[0] == 1: 
        print(0)
        exit()
    else:
        print(1)
        exit()
 

for i in range(n-1):
    if a[i] == a[i+1]:cnt+=1
    else:
        if cnt < a[i]: ans += cnt
        elif cnt > a[i]: ans += cnt-a[i]
        cnt = 1
    if i+1 == n-1:
        if cnt < a[i]: ans += cnt
        elif cnt > a[i]: ans += cnt-a[i]
print(ans)

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

def groupby():
    global a
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

b=groupby()
ans=0
for i in b:
    if i[0]>i[1]:
        ans+=i[1]
    else:
        ans+=(i[1]-i[0])

print(ans)

Solution (Python):
from collections import Counter

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

d = Counter(A)

ans = 0


for i in d.keys():
    if i != d[i]:
        if i < d[i]:
            ans += d[i] - i
        else:
            ans += d[i]
print(ans)

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

Solution (Python):
import collections

N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)
ans = 0
for val, cnt in C.items():
    if val <= cnt:
        ans += cnt - val
    else:
        ans += cnt
print(ans)

Solution (Python):
from collections import defaultdict
d = defaultdict(lambda: 0)
n=int(input())
a=list(map(int,input().split()))
for x in a:
    d[x]+=1

ans=0
for x in d:
    k=d[x]
    if k-x>=0: ans+=k-x
    else: ans+=k
print(ans)

Solution (Python):
N = int(input())
ARR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    dict = {}

    for ar in arr:
        if dict.get(ar) == None:
            dict.__setitem__(ar,1)
        else:
            tmp = dict.get(ar)
            tmp = tmp + 1
            dict.__setitem__(ar,tmp)

    sum = 0
    for k in dict.keys():

        if dict.get(k) == k:
            continue

        if dict.get(k) < k:
            sum = sum + dict.get(k)

        if dict.get(k) > k:
            sum = sum + (dict.get(k) - k)


    print(sum)


calculate(N,ARR)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

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

    ans = 0
    for aa in a_dic:
        tmp = a_dic[aa] - aa
        if tmp < 0:
            tmp = a_dic[aa]
        ans += tmp

    print(ans)

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

from collections import Counter
cntr = Counter(A)
ans = 0
for kv in cntr.items():
  
  if kv[0] <= kv[1]:
    ans += kv[1] - kv[0]
  else:
    ans += kv[1]
print(ans)

Solution (Python):
import collections

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

c = collections.Counter(A)

ans = 0
for i in set(A):
    if i > c[i]:
        ans += c[i]
    if i < c[i]:
        ans += (c[i] -i)
print(ans)

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

a.sort()
amax=a[-1]
amin=a[0]

s=[]
ai=a[0]
acnt=-1
for i in range(n):
    if a[i]>ai:
        s.append([ai,acnt+1])
        acnt=0
        ai=a[i]
    else:
        acnt=acnt+1
s.append([ai,acnt+1])
        

    
dn=0
for i in range(len(s)):
    ni=s[i][1]
    if ni>s[i][0]:
        dn=dn+(ni-s[i][0])
    elif ni<s[i][0]:
        dn=dn+ni

print(dn)

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

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

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

Solution (Python):
import collections

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

b = collections.Counter(a)
delete = 0

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

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))
def runlength(S):
    ans = []
    for s in S:
        if len(ans) == 0 or ans[-1][0] != s:
            ans.append([s,1])
        else:
            ans[-1][1] += 1
    return ans
a = runlength(a)
ans = 0
for i in range(len(a)):
  if a[i][0] < a[i][1]:
    ans += a[i][1]-a[i][0]
  elif a[i][0] > a[i][1]:
    ans += a[i][1]
print(ans)

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

c = Counter(a)

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

print(ans)

Solution (Python):
n=int(input())
a_l=sorted(map(int,input().split()))
a_l.append("!")
cnt = 1
ans = 0

for i in range(1,n+1):
    a1 = a_l[i-1]
    a2 = a_l[i]
    if a1 == a2:
        cnt += 1
    else:
        if cnt - a1 >= 0:
            ans += cnt - a1
        else:
            ans += cnt
        cnt = 1

print(ans)

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

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

num = {}

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

keys = list(num.keys())
values = list(num.values())

ans = 0
for i in range(len(keys)):
    if values[i] < keys[i]:
        ans += values[i]
    else:
        ans += values[i] - keys[i]

print(ans)

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

Solution (Python):
from collections import Counter

n = int(input())
A = Counter(map(int, input().split()))

ans = 0

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

print(ans)

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

Solution (Python):
from collections import Counter

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

res = 0
for i, c in Counter(a).items():
	res += c - i if c >= i else c
	
print(res)

Solution (Python):
from collections import defaultdict


def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    
    b_dict = defaultdict(int)
    for ai in a:
        b_dict[ai] += 1
    
    ans = 0
    for key, val in b_dict.items():
        if val < key:
            ans += val
        elif key < val:
            ans += val - key
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):

from collections import Counter

N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))


cnt_dic = Counter(a_list)

cnt=0
for i,value in cnt_dic.items():
    if i == value:
        continue
    elif i > value:
        cnt += value
    elif i < value:
        cnt += (value - i)

print(cnt)

Solution (Python):
import collections
n=int(input())
t = list(map(int,input().split()))
c = collections.Counter(t)
c1 = sorted(c.items(), key=lambda x:-x[1])
count = 0

for k,i in c1:
    if k<=i:
        count += i-k
    else:
        count += i
print(count)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [i for i in a if i <= 10**5]
ans = len(a)-len(b)
import collections
c = collections.Counter(b)
for i in range(0,10**5+1):
  if c[i] < i:
    ans += c[i]
  if c[i] > i:
    ans += c[i]-i
print(ans)

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

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

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

s=set(l)

import collections
c = collections.Counter(l)

x=0
for i in s:
    y = c[i]
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

Solution (Python):
N=int(input())
a=input().split()
numbers=[0]*10**5
A=[int(b) for b in a]
answer=0
for c in A:
    if c>10**5:
        answer+=1
    else:
        numbers[c-1]+=1
for d in range(10**5):
    if numbers[d]==0:
        continue
    elif numbers[d]==d+1:
        continue
    else:
        if numbers[d]>d+1:
            answer+=numbers[d]-d-1
        else:
            answer+=numbers[d]
print(answer)

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


ans = 0
A = Counter(a)

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

print(ans)

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

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

ans = 0
for b in B:
    v = B[b]
    if v >= b:
        ans += v - b
    else:
        ans += v
print(ans)

Solution (Python):
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
cnt=0
c=collections.Counter(a)
values=list(c.values())
key=list(c.keys())
for i in range(len(key)):
    l.append([key[i],values[i]])

for i in range(len(key)):
    if l[i][1]>l[i][0]:
        cnt=cnt+(l[i][1]-l[i][0])
    elif l[i][1]<l[i][0]:
        cnt=cnt+l[i][1]
print(cnt)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
cnt=0
for i , j in d.items():
    if i>j:
        cnt+=j
    elif i==j:
        continue
    else:
        cnt=cnt+j-i

print(cnt)

Solution (Python):

from collections import Counter
n=int(input())
a=Counter(input().split())

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

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

Solution (Python):
from collections import Counter

N = int(input())

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

dicts = Counter(lists)

ans = 0

for key in dicts.keys():
    if dicts[key] - int(key) >= 0:
        ans += dicts[key] - int(key)
    else:
        ans += dicts[key]
    
print(ans)

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

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

la = len(a)
ans = 0
for k, c in ac.items():
  if c < k:
    ans += c
  else:
    ans += c - k
    
print(ans)

Solution (Python):
from collections import defaultdict
def main():
    N = int(input())
    d = defaultdict(int)
    ans = 0
    for a in tuple(map(int,input().split())):
        d[a] += 1
    for v in d.items():
        if v[0] > v[1]:
            ans += v[1]
        else:
            ans += v[1]-v[0]
    print(ans)
if __name__ == "__main__":
    main()

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

Solution (Python):


from collections import Counter

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

num = list(set(a))
cnt = Counter(a)
ans = 0

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

print(ans)

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

for i in data:
    if d.get(i) is None:
        d[i] = 1
    else:
        d[i] += 1

ans = 0
for i, score in d.items():
    if score < i:
        ans += score
    else:
        ans += score - i

print(ans)

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

from collections import Counter
asz = Counter(a)

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

print(ans)

Solution (Python):
import collections
n = int(input())
a = collections.Counter([int(x) for x in input().split()])
res = 0
for key in a.keys():
    k_int = int(key)
    val = a[key]
    if k_int == val:
        continue
    elif k_int < val:
        res += val - k_int
    else:
        res += val
print(res)

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

a=sorted(a)
s=set(a)
count=0

base=0
judge=0

for i in a:
    if base!=i:
        
        if judge>=base:
            count+=judge-base
        else:
            count+=judge
        base=i
        judge=1
    else:
        judge+=1
if judge>=base:
    count+=judge-base
else:
    count+=judge


print(count)

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

Solution (Python):
from collections import Counter

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

c = Counter(A)

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

print(ans)

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

Solution (Python):

from collections import Counter

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

ans = 0
for i,j in aa.items():
	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()))

ACounter=Counter(A)

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

Solution (Python):
import collections

n = int(input())

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

counter = collections.Counter(a_L)

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

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt,ans=0,0
p=0
for x in a:
  if p==x:
    cnt+=1
  else:
    if cnt>p:
      ans+=cnt-p
    elif cnt<p:
      ans+=cnt
    p=x
    cnt=1
if cnt>p:
  ans+=cnt-p
elif cnt<p:
  ans+=cnt
print(ans)

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

ans = 0
for key, value in Counter(A).items():
    if key <= value:
        ans += (value - key)
    else:
        ans += value

print(ans)

Solution (Python):
def Good_Sequence(n , al):

    count = {}
    ans = 0

    for i in al:
        if i in count:
            count[i] += 1
        else:
            count[i] = 1

    for i in count.keys():
        key = int(i)
        value = int(count[i])
        if key != value:
            ans += value if value < key else abs(key - value)

    return ans

def main():
    n = int(input())
    al = list(map(int , input().split()))
    print(Good_Sequence(n , al))

if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
ans = 0
a.sort()
cnt = 1

for i in range(n-1):
    if a[i] == a[i+1]: cnt += 1
    else:
        if cnt >= a[i]: ans += cnt-a[i]
        else: ans += cnt
        cnt = 1
        
if cnt >= a[-1]: ans += cnt-a[-1]
else: ans += cnt
print(ans)

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


c=Counter(a).items()


ans=0
for i,j in c:
  if j>=i:ans+=(j-i)
  else:ans+=j

    
print(ans)

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

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

import collections

A_count = collections.Counter(A)


ans = 0
for x, x_count in A_count.items():
    if x == x_count:
        continue
    elif x < x_count:
        ans += x_count-x
    else:
        ans += x_count
print(ans)

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

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

from collections import Counter

c = Counter(a)
keys, values = zip(*c.most_common())

ans = 0

for i in range(len(keys)):
    if values[i] - keys[i] < 0:
        ans += values[i]
    else:
        ans += values[i] - keys[i]
        
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
l = set(a)
dict = {}
for x in l:
    dict.update({x:0})
for b in a:
    dict[b] += 1
ans = 0
for i in dict:
    if dict[i] < i:
        ans += dict[i]
    else:
        ans += abs(dict[i]-i)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
n = len(a)
a.sort()
a.append(-1)
ans = 0
i = 0
while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
        if i == len(a)-1:
            break
    if cnt > a[i]:
        ans += cnt - a[i]
    elif cnt < a[i]:
        ans += cnt
    i += 1
print(ans)

Solution (Python):
import collections

N = int(input())
sequence = list(map(int, input().split()))
CTR = collections.Counter(sequence).most_common()
ans = 0

for i in range(len(CTR)):
    cnt = CTR[i][1]
    obj = int(CTR[i][0])

    if (obj > cnt):
        ans += cnt
    
    else:
        ans += cnt - obj
    
print(ans)

Solution (Python):
import collections
n = int(input())
a = [int(_) for _ in input().split()]
c = collections.Counter(a).items()
ans = 0
for i in c:
    if i[0] == i[1]:
        pass
    elif i[0] > i[1]:
        ans += i[1]
    else:
        ans += i[1] - i[0]
print(ans)

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

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

print(ans)

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

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

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

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

print(ans)

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

x = a[0]
cnt = 0
ans = 0
for i in range(n):
    if x == a[i]:
       cnt += 1
    else:
        if cnt < x:
            ans += cnt
        else:
            ans += cnt - x
        x = a[i]
        cnt = 1

if cnt < x:
    ans += cnt
else:
    ans += cnt - x

print(ans)

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

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

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

i,cnt,ans=1,1,0
m=num[0]
while i<n:
    if num[i]==m:
        cnt+=1
    else:
        if cnt<m:
            ans+=cnt
        elif cnt>m:
            ans+=cnt-m
        m=num[i]
        cnt=1
    i+=1
if cnt<m:
  ans+=cnt
elif cnt>m:
  ans+=cnt-m
print(ans)

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

from collections import defaultdict
dd = defaultdict(int)

N=I()
a=LI()

a.sort()

for i in range(N):
    dd[a[i]]+=1
    
ans=0
for k,v in dd.items():
    if v>k:
        ans+=v-k
    if v<k:
        ans+=v
        
print(ans)

Solution (Python):
from collections import Counter

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

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 = [int(i) for i in input().split()]
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

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

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

counter = Counter(b_list)
ans = 0

for num, count in counter.most_common():
  if num == count:
    pass
  else:
    if num < count:
      ans += count - num
    elif num > count:
      ans += count
print(ans)

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

Solution (Python):
from collections import Counter
from collections import deque

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
c = c.most_common()
ans = 0
for num, cnt in c:
    if cnt>=num:
        ans += cnt - num
    else:
        ans += cnt
print(ans)

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

from collections import defaultdict
d = defaultdict(int)

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

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

print(ans)

Solution (Python):
import collections

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

c = collections.Counter(ls)
ans = 0

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

print(ans)

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

for i in counter:
    if i != counter[i]:
        if i < counter[i]:
            ans += counter[i] - i
        else:
            ans += counter[i]
print(ans)

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

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

Solution (Python):
import collections

N = int(input())

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


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

Solution (Python):
from collections import Counter

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

print(sum(v if v < k else v - k for k, v in Counter(A).items()))

Solution (Python):

from collections import Counter

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)
    print(sum([v if v < k else v-k for k,v in counter.items()]))
    
solve()