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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

S = set(A)
C = Counter(A)
cnt = 0
for s in S:
    if C[s] != s:
        if C[s] > s:
            cnt += C[s] - s
        else:
            cnt += C[s]
print(cnt)

Solution (Python):
def count(list):
    dict = {}
    for i in range(len(list)):
        dict[list[i]] = dict.get(list[i], 0) + 1
    return dict

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

for i, x in dic.items():
    differ = x - i
    if differ>0:
        ans += differ
    elif differ<0:
        ans += x

print(ans)

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

Solution (Python):
import collections

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

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

Solution (Python):
from collections import Counter

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

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

print(ans)

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

Solution (Python):


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

d = {}
cnt = 0 
for i in range(n):
    if a[i] not in d:
        d[a[i]] = 1 
    else: 
        d[a[i]] += 1

for key in d.keys():
    if d[key] != key:
        if d[key] < key:
            cnt += d[key]
        else:
            cnt += d[key]-key

print(cnt)

Solution (Python):
from collections import Counter

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

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

Solution (Python):
N=int(input())
lst=list(map(int,input().split()))
lst.sort()
freq={}
for i in lst:
    if i in freq:
        freq[i]+=1
    else:
        freq[i]=1
ans=0
for key,value in freq.items():
    if key>value:
        ans+=value
    elif key<value:
        ans+=abs(key-value)
print(ans)

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

cnt=[0]*(10**5+1)

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

print(ans)

Solution (Python):
from collections import Counter

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

cnt_A = Counter(A)

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

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

d = {}
for i in s:
    d[i] = 0
for i in a:
    d[i] += 1

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

Solution (Python):
import collections as c
input();print(sum(j if i>j else j-i for i,j in c.Counter(map(int,input().split())).items()))

Solution (Python):
from collections import Counter
input();print(sum(j if i>j else j-i for i,j in Counter(map(int,input().split())).items()))

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

Solution (Python):
from collections import Counter
input();a=Counter(map(int,input().split()))
print(sum(j if i>j else j-i for i,j in a.items()))

Solution (Python):
input();a=list(map(int,input().split()));d={}
for i in a:
  if i not in d: d[i]=1
  else: d[i]+=1
print(sum([j if i>j else j-i for i,j in d.items()]))

Solution (Python):
n=int(input());a=list(map(int,input().split()));d={}
for i in a:
  if i not in d: d[i]=1
  else: d[i]+=1
print(sum([j if i>j else j-i for i,j in d.items()]))

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

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

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

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

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

Solution (Python):
from collections import Counter

input()
a = Counter(map(int, input().split()))
print(sum(v - k if k <= v else v for k, v in a.items()))

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
hindo=dict()
for i in a:
    if i in hindo:
        hindo[i]+=1
    else:
        hindo[i]=1
ans=0
for num,cnt in hindo.items():
    if num==cnt:
        continue
    else:
        if num>cnt:
            ans+=cnt
        else:
            ans+=cnt-num
print(ans)

Solution (Python):
import collections as c
N,*A = map(int,open(0).read().split())
A = c.Counter(A)
ans=0
for a,n in A.items():
  if a<n:
    ans+=n-a
  elif a>n:
    ans+=n
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=dict()
for x in a:
  if x in b:
    b[x] += 1
  else:
    b[x] = 1
ans = 0
for k, v in b.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()))
d = dict()
for i in a:
    if i not in d:
        d[i] = 1

    else:
        d[i] += 1
count = 0
for key, value in d.items():
    if int(key) > value:
        count += int(value)
    elif int(key) < value:
        count += value - int(key)

print(count)

Solution (Python):
from collections import Counter

n,*a=map(int,open(0).read().split())

cnt=Counter(a)

ans=0

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

print(ans)

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

values = {}
cnt = n

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

    if values[a[i]] == a[i]:
            cnt -= a[i]

print(cnt)

Solution (Python):
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    adic = dict()
    ans = 0

    for i in range(n):
        a = inlis[i]
        if a not in adic:
            adic[a] = 1
        else:
            adic[a] += 1
        if adic[a] > a:
            ans += 1
    
    for num in adic:
        if adic[num] < num:
            ans += adic[num]

    print(ans)
            

        


if __name__ == "__main__":
    main()

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

for ai in a:
    if ai not in cnt.keys():
        cnt[ai] = 1
    else:
        cnt[ai] += 1

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

Solution (Python):
from collections import Counter

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

CD = Counter(D)
CD=list(CD.items())
count=0
for i in range(len(CD)):
    if CD[i][0]<CD[i][1]:
        count=count+CD[i][1]-CD[i][0]
    elif CD[i][0]>CD[i][1]:
        count=count+CD[i][1]
print(count)

Solution (Python):
from collections import Counter

N=input()
list1=list(map(int,input().split()))
dict1=Counter(list1)

key1=list(dict1.keys())
value1=list(dict1.values())

ans=0
for i in range(len(key1)):
    x=value1[i]
    y=key1[i]
    if x>=y:
        ans+=x-y
    else:
        ans+=x

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):

import sys


def solve(N: int, a: "List[int]"):
    from collections import Counter
    ans = 0
    for k, v in Counter(a).items():
        ans += v - k if v >= k else v
    return ans



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    print(solve(N, a))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

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

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

Solution (Python):
N=int(input())
a=map(int,input().split())
ans,d=0,{}
for x in a:
    d[x]=d.get(x,0)+1
    ans+=1
    if d[x]==x:
        ans-=x
print(ans)

Solution (Python):
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
ke=list(Counter(L).values())
val=list(Counter(L).keys())
ans=0
for i in range(len(val)):
  if val[i]>ke[i]:
    ans+=ke[i]
  else:
    ans+=ke[i]-val[i]
print(ans)

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

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

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

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



N = int(input())
A = Counter(list(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):

from collections import Counter





def solve(n,a):
  d = Counter(a)
  res = 0
  for k,v in d.items():
    if k <= v:
      res += v-k
    else:
      res += v
  return res



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

if __name__ == '__main__':
  main()

Solution (Python):
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
ans = 0
for x, y in A.items():
  if y >= x:
    ans += y - x
  else:
    ans += y
print(ans)

Solution (Python):
import sys
from collections import Counter

read=sys.stdin.read

n,*a=map(int,read().split())
ca=Counter(a)
ans=0
for x in iter(ca):
  if ca[x]<x:
    ans+=ca[x]
  elif ca[x]>x:
    ans+=ca[x]-x
print(ans)

Solution (Python):



def main():
    from collections import Counter

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

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    from collections import Counter

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

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
def main():
    N = int( input())
    A = list( map( int, input().split()))
    d = defaultdict( int)
    for a in A:
        d[a] += 1
    ans = 0
    for key, value in d.items():
        if key > value:
            ans += value
        elif key < value:
            ans += value - key
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)


input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])

    def search(self, s, g):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]


def solve():
    n = getN()
    nums = getList()
    c = Counter(nums)
    ans = 0
    for k, v in c.items():
        if v < k:
            ans += v
        elif v > k:
            ans += v - k
    print(ans)
    return
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

Solution (Python):
import collections


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

c = collections.Counter(A)

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

print(ans)

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

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

Solution (Python):
from collections import Counter

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

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

Solution (Python):
import collections
n,cc = raw_input(), collections.Counter(map(int, raw_input().split()))
print sum([(cc[k] - k if k <= cc[k] else cc[k]) for k in cc] or [0])

Solution (Python):
import collections

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

B = dict(collections.Counter(A))
M = len(B)

ans = 0

for i in B.keys():
    if B[i] >= int(i):
        ans += B[i] - int(i)
    else:
        ans += B[i]

print(ans)

Solution (Python):
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    counter = Counter(A)

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np


N = int(input().split()[0])
sequence = np.array(list( map(int, input().split()) ))


remove = np.sum(sequence>N)
sequence = sequence[sequence<=N]

index = np.unique(sequence)

for idx in index:

    n_idx = np.sum(sequence==idx)
    if n_idx < idx:
        remove += n_idx
    else:
        remove += (n_idx-idx)

print(remove)

Solution (Python):
from collections import Counter
n=int(input())
sc=Counter(list(map(int,input().split())))
sm=0
for k,v in sc.items():
  sm+=min(v,(v-k if v-k>=0 else 10**9+1)) 
print(sm)

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

for x in range(n):
  if a[x] not in d:
    d[a[x]]=0
  d[a[x]]+=1
  
ans=0
for y in d:
  if d[y]>y:
    ans+=d[y]-y
  elif d[y]<y:
    ans+=d[y]
    
print(ans)

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

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

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

Solution (Python):
n = int(input())
alst = list(map(int, input().split()))
cnt = [0 for _ in range(n)]
for a in alst:
    if a > n:
        continue
    cnt[a - 1] += 1

rem = 0
for i, num in enumerate(cnt, start = 1):
    if num >= i:
        rem += i
        
print(n - rem)

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
c = Counter(list(l())).most_common()
for i in c:
    if i[0]>i[1]:
        cnt+=i[1]
    else:
        cnt+=i[1]-i[0]

print(cnt)

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

dd=defaultdict(lambda:0)
for aa in a: dd[aa]+=1

ans=0
for aa in dd.keys():
  ca=dd[aa]
  if ca>=aa:
    ans+=ca-aa
  else:
    ans+=ca
print(ans)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
m={}
for i in range(N):
  if A[i] in m:
    m[A[i]] += 1
  else:
    m[A[i]] = 1
ans = 0
for k,n in m.items():
  if k <= n:
    ans += n-k
  else:
    ans += n
print(ans)

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

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

Solution (Python):
from collections import Counter

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

c = Counter(lis)

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

print(ans)

Solution (Python):
from collections import Counter

N = int(input())

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

a = Counter(a)

ans = 0
for i in a:
    if i <= a[i]:
        ans+=a[i]-i
    else:
        ans+=a[i]

print(ans)

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

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

counter = Counter(A)
ans = 0
for value, count in counter.items():
    if count > value:
        ans += count - value
    elif count < value:
        ans += count

print(ans)

Solution (Python):
import collections
N = int(input())
A = collections.Counter(int(T) for T in input().split()).most_common()
Remove = 0
for T in range(0,len(A)):
    if A[T][0]>A[T][1]:
        Remove += A[T][1]
    elif A[T][0]<A[T][1]:
        Remove += A[T][1]-A[T][0]
print(Remove)

Solution (Python):

from collections import Counter
n, *a = map(int, open(0).read().split())
c = Counter(a)
ans = 0
for k, v in c.items():
    ans += v - k if v >= k else v
print(ans)

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

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

K=0
for b in T:
    if T[b]<b:
        K+=T[b]
    elif b<T[b]:
        K+=T[b]-b
print(K)

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

B = [0]*100001

for i in range (0, N):
	if A[i] <= 100000:
		B[A[i]]+=1
	else:
		count+=1

for i in range (1, 100001):
	if B[i] < i:
		count+=B[i]
	if B[i] > i:
		count+=(B[i]-i)

print(count)

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

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

print(ans)

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

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

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

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

print(res)

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

Solution (Python):
from collections import Counter
n=int(input())
a=list(Counter(list(map(int,input().split()))).items())
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=Counter(list(map(int,input().split()))).most_common()
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 defaultdict
d = defaultdict(int)

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

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

ans = 0
for k,v in d.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()))
b=Counter(a)
count=0
for i in b:
    if b[i]<i:
        count+=b[i]
    else:
        count+=(b[i]-i)
print(count)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    from collections import Counter
    c = Counter(a)
    cnt = 0
    for i,j in c.items():
        if i == 1:
            cnt += max(j-1,0)
        else:
            cnt += j%i
    print(cnt)

if __name__ == '__main__':
    main()

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

Solution (Python):
import collections


def main():
    N = int(input())
    A = list(map(int, input().split()))
    counter = collections.Counter(A)
    ans = 0
    for k, v in counter.items():
        if v > k:
            ans += v - k
        elif v < k:
            ans += v
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    ans = 0
    for key in d:
        if d[key] < key:
            ans += d[key]
            continue
        ans += d[key] - key
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter
def main():
    N = int(input())
    A = list(input().split())
    C = Counter(A)
    ans = 0
    for k, v in C.items():
        if v >= int(k):
            ans += v - int(k)
        else:
            ans += v
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections

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

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]] = dict[a[i]] + 1
    else:
        dict[a[i]] = 1

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

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

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

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = (10**5+1)*[0]
ans = 0

for a in A:
  if a<=10**5:
    B[a]+=1
  else:
    ans+=1

for n in range(10**5):
  if B[n]<n:
    ans+=B[n]
  elif n<B[n]:
    ans+=B[n]-n

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
counter =dict(Counter(a))
c_key =list(counter.keys())
c_value =list(counter.values())
cnt = 0
sl = len(c_value)
for i in range(sl):
  if int(c_key[i]) <  c_value[i]:
      cnt += (c_value[i]- int(c_key[i]))
  elif int(c_key[i]) >  c_value[i]:
 	  cnt += c_value[i] 
print(cnt)

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

Solution (Python):
inputs = [input() for i in range(2)]
n = int(inputs[0])
a = map(lambda x: int(x), inputs[1].split(" "))

b = {}
for i in a:
  if i not in b:
    b[i] = 1
  else:
    b[i] += 1
count = 0
for k in b.keys():
  tmp = k - b[k]
  if tmp > 0:
    count += b[k]
  else:
    count += -tmp


print(count)

Solution (Python):
import numpy as np
def main():
  N = int(input())
  A = list(map(int, input().split()))
  dic = {}
  for i in range(N):
    if not A[i] in dic:
      dic[A[i]]=1
    else:
      dic[A[i]]+=1
  ans = 0
  for i, j in dic.items():
    if i < j:
      ans += j-i
    if j < i:
      ans += j
  print(ans)
  
if __name__ == "__main__":
  main()

Solution (Python):
from collections import Counter

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

num_removal = 0
for digit, count in Counter(a).items():
    if digit > count:
        num_removal += count
    else:
        num_removal += (count - digit)
print(num_removal)

Solution (Python):






import collections





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





mycnt = collections.Counter(a)
ans = 0
for x,cnt in mycnt.items():
    if x > cnt:
        ans += cnt
    else:
        ans += cnt - x
print(ans)

Solution (Python):
N = input()

num = {}
for a in map(int, input().split()):
  if not a in num.keys(): num[a] = 1
  else: num[a] += 1

res = 0
for a, a_num in num.items():
  if a_num < a: res += a_num
  else: res += a_num - a
print(res)