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



Sample input:
4
3 3 3 3


Sample output:
1

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
for i in a:
  if i not in d:
    d[i]=0
  d[i]+=1
c=0
for i in set(a):
  n=d[i]
  c+=n if n<i else n-i
print(c)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
a = dict()
for i in arr:
    if i in a.keys():
        a[i] += 1
    else:
        a[i] = 1
ans = 0
for i in a.keys():
    if a[i] < i:
        ans += a[i]
    elif a[i] > i:
        ans += a[i] - i
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)
n = int(input())
ns = map(int, input().split())
for i in ns:
    dic[i] += 1
result = 0
for key, value in dic.items():
    if key < value:
        result += value - key
    elif key > value:
        result += value
print(result)

Submission status: Accepted

Solution code:
N = int(input())
seq = list(map(int, input().split()))

d = {}
for i in range(0,N):
    e = seq[i]
    if e not in d.keys():
        d[e] = 1
    else:
        d[e] += 1

r = 0
for k in d.keys():
    v = d[k]
    if (v < k):
        r += v
    else:
        r += v-k

print(r)

Submission status: Accepted

Solution code:
n = int(input())
seq = [int(x) for x in input().split()]

if len(seq) == 1:
  if seq[0] == 1:
    print("0")
  else:
    print("1")
else:
  total = 0
  counts = {}
  for x in seq:
    if x not in counts:
      counts[x] = 1
    else:
      counts[x] += 1

  for key,val in counts.items():
    if val < key:
      total += val
    else:
      total += abs(key-val)
  print(total)

Submission status: Accepted

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

Submission status: Accepted

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

aa = collections.Counter(a)
ans = 0
for i in aa:
    if i != aa[i]:
        if aa[i] < i:
            ans += aa[i]
        else:
            ans += aa[i] - i
print(ans)

Submission status: Accepted

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

c = Counter(a)
ans = 0
for i in c.items():
    if i[0]>i[1]:
        ans += i[1]
    elif i[0]<i[1]:
        ans += i[1]-i[0]

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc082/tasks/arc087_a
# 16:20-16:26 done


def main():
    N = int(input())
    a = list(map(int, input().split()))
    
    num_cnt = {}
    for num in a:
        if num in num_cnt:
            num_cnt[num] += 1
        else:
            num_cnt[num] = 1
    
    ans = 0
    for num, cnt in num_cnt.items():
        if cnt >= num:
            ans += cnt - num
        else:
            ans += cnt

    return ans


print(main())

Submission status: Accepted

Solution code:
url = "https://atcoder.jp/contests/abc082/tasks/arc087_a"
import copy
def main():
    n = int(input())
    li = list(map(int, input().split()))
    inds = {}
    ans = 0
    for i in range(len(li)):
        inds.setdefault(li[i], 0)
        inds[li[i]] += 1
    for k, v in inds.items():
        if k == v:
            pass
        elif k > v:
            ans += v
        elif k < v:
            ans += v - k
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
list_A = list(map(int, input().split()))
l = Counter(list_A)
ans = 0
for s, i in l.items():
    if i >= s:
        ans += i - s
    else:
        ans += i

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
set_a = list(set(list_A))
dic_A = dict()

for i in range(len(set_a)):
    j = str(set_a[i])
    dic_A[j] = 0

for i in list_A:
    j = str(i)
    dic_A[j] += 1
ans = 0
for s, i in dic_A.items():
    c = int(s)
    if i >= c:
        ans += i - c
    else:
        ans += i

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

    ans = 0
    for dd in d:
        if dd < d[dd]:
            ans += d[dd] - dd
        elif dd > d[dd]:
            ans += d[dd]

    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = Counter([int(x) for x in input().split()])
res = 0
for a in A.keys():
    res += A[a] - a * (A[a] >= a)
print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
ans = 0
for k, v in c.items():
    if k <= v:
        ans += v-k
    else:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
a.append(0)
ans,x,count=0,a[0],0
for i in a:
  if x==i:
    count+=1
  else:
    ans+=count if count<x else count-x
    count=1
    x=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = 0
A = Counter(list(map(int,input().split())))
for i in A.items():
  a = i[0]
  b = i[1]
  if a<=b:
    c += b-a
  else:
    c += b
print(c)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
num_cnt = {}
for i in range(N):
    if a[i] in num_cnt:
        num_cnt[a[i]] += 1
    else:
        num_cnt[a[i]] = 1
cnt = 0
for i, j in num_cnt.items():
    if j >= i:
        cnt += j - i
    else:
        cnt += j
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    ctr = Counter(a)
    print(sum(nn if n > nn else nn - n for n, nn in ctr.items()))


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

n = int(input())
a_lst = [int(elem) for elem in input().split()]

c = collections.Counter(a_lst)
cnt = 0

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

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))

count = {}

for i in lst:
    if i in count.keys():
        count[i]+=1
    else:
        count[i]=1
# print(count)

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

Submission status: Accepted

Solution code:
import collections

n, *a = map(int, open(0).read().split())
c = collections.Counter(a)
cnt = 0
for s in c.keys():
    if s < c[s]:
        cnt += c[s] - s
    elif s > c[s]:
        cnt += c[s]
print(cnt)

Submission status: Accepted

Solution code:
import collections

n, *a = map(int, open(0).read().split())
c = collections.Counter(a)
cnt = 0
for s in c.keys():
    s_num = c[s]
    if s < s_num:
        cnt += s_num - s
    elif s > s_num:
        cnt += s_num
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = input().split()
dic = defaultdict(int)
for a in A:
    dic[int(a)] += 1
ans = 0
for i, v in dic.items():
    if i < v:
        ans += v - i
    elif i > v:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import collections
n = int(input())
a = [int(i) for i in input().split()]

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
ans = 0
for x, y in d.items():
  ans += y if x > y else y - x
print(ans)

Submission status: Accepted

Solution code:
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
a = inputlist()
c = Counter(a)
key = c.keys()
ans = 0
for i in key:
    if c[i] == i:
        continue
    if c[i] > i:
        ans += c[i]-i
    if c[i] < i:
        ans +=c[i]
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
a.sort()
b = sorted(list(set(a)))
idx = 0
cnt = [0 for _ in range(len(b))]
for i in range(n):
    if a[i] != b[idx]:
        idx += 1
    cnt[idx] += 1
ans = 0
for i in range(len(b)):
    tmp = cnt[i] - b[i]
    if tmp < 0:
        tmp = cnt[i]
    ans += tmp
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    input()
    aa=LI()
    cc=Counter(aa)
    ans=0
    for a,c in cc.items():
        if a>c:ans+=c
        else:ans+=c-a
    print(ans)

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
n, *a = map(int, open(0).read().split())
a = Counter(a).items()
ans = 0
for v,c in a:
	if v<=c: ans += c-v
	else: ans += c
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N=int(input())
A=list(map(int,input().split()))
M=collections.Counter(A)
tmp=0
for i,j in M.items():
	if i>j:
		tmp+=j
	else:
		tmp+=(j-i)
print(tmp)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for val, cnt in c.most_common():
    if val > cnt:
        ans += cnt
    elif val < cnt:
        ans += cnt - val
print(ans)

Submission status: Accepted

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

a=sorted(a)
base={}
count=0

for i in range(N):
    if a[i] not in base.keys():
        base[a[i]]=1
        if i>=1 and base[a[i-1]]<a[i-1]:
            count+=base[a[i-1]]
    else:
        if base[a[i]]>=a[i]:
            count+=1
        else:
            base[a[i]]+=1
if base[a[N-1]]<a[N-1]:
    count+=base[a[i]]
print(count)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a_count = collections.Counter(a)
# print(a_count)
ans = 0
for i, j in a_count.items():
    # print(i, j)
    if i <= j:
        ans += j - i
    else:
        ans += j

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
a = int(input())
b = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in b:
    d[i]+=1
ret = 0
for k,v in d.items():
    if v>=k:
        ret+=(v-k)
    else:
        ret+=v
print(ret)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    
    res = 0
    for k in d.keys():
        if d[k] >= k:
            res += d[k] - k
        else:
            res += d[k]
    
    print(res)
    
    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

C = Counter(A)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = {}
for x in a:
    if x not in cnt:cnt[x] = 1
    else: cnt[x] += 1
ans = 0
for key in cnt:
    if cnt[key] >= key:
        ans+= cnt[key] - key
    else:ans += cnt[key]
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

from collections import Counter

c = Counter(a)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.append(-1)
n = 0
cnt = 0
ans = 0
for a in A:
    if a == n:
        cnt += 1
    else:
        if cnt >= n:
            ans += cnt - n
        else:
            ans += cnt
        n = a
        cnt = 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    AD = dict()
    for a in A:
        if a in AD: AD[a] += 1
        else: AD[a] = 1

    count = 0
    for key in AD:
        if AD[key] == key: continue
        elif AD[key] > key: count += AD[key] - key
        else: count += AD[key]
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    ans = 0
    c = Counter(A)
    for k, v in c.items():
        if k < v:
            ans += v - k
        elif v < k:
            ans += v
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
c = Counter(a)
res = 0
for key in c.keys():
    # print(key)
    if c[key] >= key:
        res += c[key] - key
    else:
        res += c[key]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

from collections import Counter

Acnt = Counter(A)

ans = 0
for key,cnt in Acnt.items():
    if key == cnt:
        pass
    elif key < cnt:
        ans += cnt - key
    else:
        ans += cnt
    
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    ans = 0
    for i in set(a):
        if d[i] < i:
            ans += d[i]
        else:
            ans += d[i]-i
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import collections

c=collections.Counter(a)
#print(dict(c))

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
#l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
#c = Counter(l)
#print(c)   # Counter({'a': 4, 'c': 2, 'b': 1})

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

d = Counter(A)

ans = 0
# print(d)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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