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: Wrong Answer

Solution code:
n = int(input())
aList = list(map(int, input().split()))
aLen = len(aList)

aSet = list(set(aList))
aSum = 0
for a in aSet:
    if a > aLen:
        aSum += aLen
        break
    aCount = aList.count(a)
    if aCount > a:
        aSum += aCount - a
    if aCount < a:
        aSum += aCount
    aLen -= aCount
print(aSum)

Submission status: Wrong Answer

Solution code:
from collections import Counter as ct

n=int(input())
lists=list(map(int,input().split()))
wanted=dict(ct(lists))
print(wanted)
if n>=2:
    numbers=0
    for i in wanted.keys():
        a=i-wanted[i]
        if a<0:
            numbers+=abs(a)
        elif a==0:
            numbers+=0
        if a>0:
            numbers+=wanted[i]
    print(numbers)
elif n==1:
    if lists==[1]:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
hoge = Counter(a)
cnt = 0
for key, value in hoge.items():
  if value > key:
    cnt += value
  else:
    cnt += value - key    
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
hoge = Counter(a)
cnt = 0
for key, value in hoge.items():
  cnt += value - key if value - key > 0 else value
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
hoge = Counter(a)
cnt = 0
for key, value in hoge.items():
  cnt += min([value - key, value])
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
hoge = Counter(a)
cnt = 0
for key, value in hoge.items():
  cnt += min([key - value, value])
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
hoge = Counter(a)
cnt = 0
for key, value in hoge.items():
  fuga = abs(key - value)
  cnt += min([fuga, value])
print(cnt)

Submission status: Wrong Answer

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

C = [0] * N # [1の個数, 2の個数, 3の個数, ... , Nの個数]
for i in range(N):
  n = A[i]
  if n <= N:
    C[n-1] += 1

ans = 0
for i in range(N):
  cnt = C[i]
  if cnt > i+1:
    ans += (cnt - (i+1))
  elif cnt < i+1:
    ans += cnt

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input().strip())
counter_A = Counter(map(int, input().strip().split(' ')))
ans = 0
for k,v in counter_A.items():
  if k >= v:
    ans += v-k
  else:
    ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in b:
    nc=0
    for j in a:
        if j==i:
          nc+=1
        else:
          nc+=0    
    er = nc - i
    if er<0:
        c+= er+i
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in b:
    nc=0
    for j in a:
        if j==i:
          nc+=1
        else:
          nc+=0    
    er = nc - i
    if er<0:
        c+= er+i

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in range(len(b)):
    if  a.count( b[i] ) - b[i] <= 0:
      c+=a.count( b[i] ) - b[i] 
    else:
      c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
for i in a_set:
    print(i)
    if int(a.count(str(i))) >= int(i):
        
        cnt +=  (int(a.count(str(i))) - int(i))
    elif  int(a.count(str(i))) < int(i):
        cnt +=  int(a.count(str(i)))
print(cnt)

Submission status: Wrong Answer

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

c=Counter(A)
ans=0
for key, value in c.items():
  print(key,value)
  if key!=value:
    if key>value:
      ans+=value
    else:
      ans+=value-key
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import*;print(sum(v if v<k else v-k for k,v in Counter(map(int,open(0).read().split())).items())-1)

Submission status: Wrong Answer

Solution code:
# C - Good Sequence
import collections
N = int(input())
a = list(map(int, input().split()))
count = 0

a_1 = collections.Counter(a)

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

print(count)

Submission status: Wrong Answer

Solution code:
import collections

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

for i,j in a.items():
    if i != j:
        ans += min(abs(i - j), j)
print(ans)

Submission status: Wrong Answer

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

    if i == n - 1:
        if cnt < a[i]:
            ans += cnt
        elif cnt > a[i]:
            ans += cnt - a[i]

print(ans)

Submission status: Wrong Answer

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

    if i == n - 1:
        if cnt < a[i]:
            ans += cnt
        elif cnt > a[i]:
            ans += cnt - a[i]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n == 1:
    print(1)
    exit()

set_a = set(a)
count = 0

for i in set_a:
    if a.count(i) > i:
        count += a.count(i) - i
    elif a.count(i) < i:
        count += a.count(i)

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
set_a = set(a)
count = 0

for i in set_a:
    if n == 1:
        count = 1
    elif a.count(i) != i:
        if a.count(i) > i:
            count += a.count(i) - i
        else:
            count += a.count(i)

print(count)

Submission status: Wrong Answer

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

for v in a:
    try:
        d[v] += 1
    except:
        d[v] = 1

ans = 0
for key in d.keys():
    ans += min(abs(d[key] - key), d[key])
print(ans)

Submission status: Wrong Answer

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

for v in a:
    try:
        d[v] += 1
    except:
        d[v] = 1

ans = 0
for key in d.keys():
    ans += min(abs(key - d[key]), d[key])
print(ans)

Submission status: Wrong Answer

Solution code:
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+=min(abs(i-j),j)
print(ans)

Submission status: Wrong Answer

Solution code:
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+=min(abs(i-j),i,j)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
C=collections.Counter(A)
print(abs(sum(C.values())-sum(C.keys())))

Submission status: Wrong Answer

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

kouho = [0] * (n + 1 )

ans = 0

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

for i in range(n+1):
    if kouho[i] != 0:
        #print(kouho[i],i)
        ans += min(abs(i-kouho[i]),kouho[i])
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = [0] * 100007
count = 0
total = 0

for i in range(N):
    if A[i] < 100007:
        C[int(A[i])] += 1

for i in range(1, min(N, len(C))):
    count += C[i]
    if C[i] < i:
        total += C[i]
    if C[i] > i:
        total += C[i] - i

print(total + N - count)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
C=[0]*1000
count=0
total=0


for i in range(N):
    if A[i]<1000:
        C[int(A[i])]+=1

for i in range(1,min(N,len(C))):
    count+=C[i]
    if C[i]<i:
        total+=C[i]
    if C[i]>i:
        total+=C[i]-i

print(total+N-count)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
C=[0]*500
count=0
total=0


for i in range(N):
    if A[i]<500:
        C[int(A[i])]+=1

for i in range(1,min(N,len(C))):
    count+=C[i]
    if C[i]<i:
        total+=C[i]
    if C[i]>i:
        total+=C[i]-i

print(total+N-count)

Submission status: Wrong Answer

Solution code:
import collections

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

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += ai - c[ai]

print(ans)

Submission status: Wrong Answer

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

ans = 0
c19 = 0
for i in range(1,10):
    ca = a.count(i)
    if ca >= i:
        ans += ca - i
    else:
        ans += ca
    c19 += ca
print(ans + n-c19)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for key,value in c.items():
    ans += min(abs(value-int(key)), abs(value))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for key,value in c.items():
    ans += min(abs(key-value), abs(value))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for key,value in c.items():
    ans += min(abs(value - key), abs(value))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = input()
c = Counter(map(int, input().split()))
print(sum([v if k < v else v - k for k,v in c.items()]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = input()
c = Counter(map(int, input().split()))
print(sum([min(abs(c[key] - key), c[key]) for key in c]))

Submission status: Wrong Answer

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

A_set = list(set(A))
ans = 0
for i in range(len(A_set)):
  nm = A_set[i]
  nm_cnt = A.count(nm)
  if nm > N:
    ans += nm_cnt
  
  if nm_cnt < nm:
    ans += nm_cnt
  elif nm_cnt > nm:
    ans += nm_cnt - nm
  N -= nm_cnt

print(ans)

Submission status: Wrong Answer

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

A_set = list(set(A))
ans = 0
for i in range(len(A_set)):
  nm = A_set[i]
  if nm > N:
    ans += nm
    continue
  
  nm_cnt = A.count(nm)
  if nm_cnt < nm:
    ans += nm_cnt
  elif nm_cnt > nm:
    ans += nm_cnt - nm
  else:
    continue

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC82 C

from collections import Counter

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

b = Counter(a)
b = list(b.items())
ans = 0
for i,j in b:
    ans += min(abs(i-j),j)
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
for i in a:
    d[i]=d.get(i,0)+1
print(d)
print(sum(d[i]-i*(d[i]>=i)for i in d))

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
d = dict()
for a in arr:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

count = 0
for k, v in d.items():
    if k != v:
        count += v
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
d = dict()
for a in arr:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

count = 0
for k, v in d.items():
    if k != v:
        count += min(abs(k-v), v)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
d = dict()
for a in arr:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

a = list(sorted(d.items(), key=lambda x: x[0]))
count = 0
for av in a:
    if av[0] != av[1]:
        count += min(abs(av[1] - av[0]), av[1])

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

hash = {}

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

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


print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

for i in a:
    d[i] += 1
cnt = 0

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

Submission status: Wrong Answer

Solution code:
N = input()
d = dict()
for x in map(int, input().split()):
  if d.get(x) is None:
    d[x] = 0
  d[x] += 1

print(sum((min(d[x], abs(d[x]-x)) for x in d)))

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = sorted(list(map(int, input().split())))+[0]

ans = 0
num = arr[0]
cnt = 0

for i in arr:
        if i == num: cnt += 1
        else:
                ans += min(cnt, abs(cnt-num))
                cnt = 1
                num = i
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, a: "List[int]"):
    counter = Counter(a)

    ans = 0
    for key in counter:
        ans += min(abs(key-counter[key]), counter[key])
        b = min(abs(key-counter[key]), counter[key])
        # print(key, counter[key], b)
    print(ans)
    return


a = []
for i in range(1, 10):
    a.extend([i]*3)

counter = Counter(a)


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: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, a: "List[int]"):
    counter = Counter(a)

    ans = 0
    for key in counter:
        if counter[key] <= key:
            ans += min(key-counter[key], counter[key])
        else:
            ans += counter[key]-key
    print(ans)
    return


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: Wrong Answer

Solution code:
N = int(input())
a = sorted([int(x) for x in input().split()])
i,ans = 0,0
while i < N:
    c = a.count(a[i])
    if c > a[i]:
        ans += min(c-a[i],a[i])
    elif c < a[i]:
        ans += c
    i += c

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, *a = map(int, open(0).read().split())
c = Counter(a)
ans = 0
for v in c:
  if v > c[v]:
    ans += c[v]
  else:
    ans += v - c[v]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, *a = map(int, open(0).read().split())
c = Counter(a)
print(sum(abs(min(v - c[v], c[v])) for v in c))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, *a = map(int, open(0).read().split())
c = Counter(a)
print(sum(min(abs(v - c[v]), c[v]) for v in c))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, *a = map(int, open(0).read().split())
c = Counter(a)
print(sum(abs(v - c[v]) for v in c))

Submission status: Wrong Answer

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

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

for i in a:
    if i <= 10**5:
        cnt[i-1] += 1

c = 0

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

print(c)

Submission status: Wrong Answer

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

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

for i in a:
    if i < 10**5:
        cnt[i-1] += 1

c = 0

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

print(c)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math
import collections
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = list(int(_) for _ in input().split())
    a.sort()
    d = collections.defaultdict(int)
    for a_i in a:
        d[a_i] +=1
    ans = 0
    for k,v in d.items():
        ans += min(v,abs(k-v))
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N=int(input())
  l=LI()

  if N==1 and l[0]==1000000000:
    exit()

  l.sort()
  l.append(inf)

  c=0
  a=l[0]
  cnt=1
  for x in l[1:]:
    if a==x:
      cnt+=1
    else:
      if a<cnt:
        c+=cnt-a
      elif a==cnt:
        pass
      else:
        c+=cnt
      a=x
      cnt=1

  print(c)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = np.array(list(map(int,input().split())))
a = a[a<10**5]
count = 0#空集合用

count += N - len(a)

for i in range (10**5):
    num = len(np.where(a == i)[0])
    if num !=0:
        if num >i:
            count += (num-i)
        elif num < i:
            count += num

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=list(map(int,input().split()))
while len(list) != 0and max(list) >= len(list):
    list = [i for i in list if i < len(list)]
#list2 = [i for i in list if i < N]
cnt=0
for i in range(1,len(list)+1):
    if list.count(i) > i:
        cnt +=list.count(i)-i
    elif list.count(i) < i:
        cnt +=list.count(i)
print(N-len(list)+cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=list(map(int,input().split()))
while len(list) != 0and max(list) >= len(list):
    list = [i for i in list if i < len(list)]
#list2 = [i for i in list if i < N]
cnt=0
for i in range(1,len(list)):
    if list.count(i) > i:
        cnt +=list.count(i)-i
    elif list.count(i) < i:
        cnt +=list.count(i)
print(N-len(list)+cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
b = list(set(a))
for i in b:
    if not a.count(i) == i:
        d = a.count(i)
        # print(d-i,d,i-d)
        # if d > i:
        #     ans += d-i
        # else:
        #     if i - d > i:
        #         ans += i-d
        #
        #     else:
        #         ans += d
        c = [d-i,d,i-d]
        f = 10000000000
        for g in c:
            if g <= 0:
                continue
            elif f > g:
                f = g
        else:
            ans += f

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=list(map(int,input().split()))
while len(list) != 0and max(list) > len(list):
    list = [i for i in list if i < len(list)]
#list2 = [i for i in list if i < N]
cnt=0
for i in range(1,len(list)):
    if list.count(i) > i:
        cnt +=list.count(i)-i
    elif list.count(i) < i:
        cnt +=list.count(i)
print(N-len(list)+cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l2=set(l)
c=0
for i in l2:
  if i>l.count(i):
    c+=l.count(i)
  else:
    c+=l.count(i)-i

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

num = Counter(a).most_common()

for i, j in num:
    sum += abs(i - j)

print(sum)

Submission status: Wrong Answer

Solution code:
N = input()

cnt = 0
strdit = {}
for i in input().split():
    i = int(i)
    if i not in strdit.keys():
        strdit[i] = 0
    strdit[i] += 1

for i in strdit.keys():
    cnt += min(abs(0-strdit[i]), abs(i-strdit[i]))

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
strdit = {}
for i in input().split():
    if int(i) not in strdit.keys():
        strdit[int(i)] = 0
    strdit[int(i)] += 1

for i in strdit.keys():
    if strdit[i] != 0:
        cnt += min(abs(0-strdit[i]), abs(i-strdit[i]))

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

cnt = 0
strdit = {}
for i in input().split():
    if int(i) not in strdit.keys():
        strdit[int(i)] = 0
    strdit[int(i)] += 1

for i in strdit.keys():
    if strdit[i] != 0:
        if i > strdit[i]:
            cnt += 1
        else:
            cnt += abs(i-strdit[i])

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
d =  {}
a = list(map(int,input().split()))
for i in range(N):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] +=1
ans = 0
for k,v in d.items():
    ans += max(0,v-k)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
ans=0
for i in d.keys():
  if i>=d[i]:
    ans+=i-d[i]
  else:
    ans+=i
print(ans)

Submission status: Wrong Answer

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

b = list(set(a))

ans = 0
for i in b:
    if i > N:
        continue
    if a.count(i) < i:
        ans += a.count(i)
    else:
        ans += a.count(i) - i

print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/04/19
# AtCoder Beginner Contest 082 - C

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

a.sort()
a.reverse()
#a = sorted(ia, reverse=True)

cnt = 1
ans = 0
wkval = a[0]

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

if cnt > 1:
    if wkval < cnt:
        ans += cnt - wkval
    elif wkval > cnt:
        ans += cnt

if n == 1 and wkval > 1:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/04/19
# AtCoder Beginner Contest 082 - C

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

a.reverse()
#a = sorted(ia, reverse=True)

cnt = 1
ans = 0
wkval = a[0]

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

if cnt > 1:
    if wkval < cnt:
        ans += cnt - wkval
    elif wkval > cnt:
        ans += cnt

if n == 1 and wkval > 1:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/04/19
# AtCoder Beginner Contest 082 - C

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

a = sorted(ia, reverse=True)

cnt = 1
ans = 0
wkval = a[0]

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

if cnt > 1:
    if wkval < cnt:
        ans += cnt - wkval
    elif wkval > cnt:
        ans += cnt

if n == 1 and wkval > 1:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/04/19
# AtCoder Beginner Contest 082 - C

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

a.sort()

cnt = 1
ans = 0
wkval = a[0]

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

if cnt > 1:
    if wkval < cnt:
        ans += cnt - wkval
    elif wkval > cnt:
        ans += cnt

if n == 1 and wkval > 1:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import*;n,*a=map(int,open(0).read().split());print(sum(min(abs(v-k),v)for k,v in Counter(a).items()))

Submission status: Wrong Answer

Solution code:
#ABC082C
N = int(input())
remove_count = 0
number_count = 1
a = list(map(int, input().split()))
a.sort()
for i in range(N-1):
    if a[i] == a[i+1] and i > N-2:
        number_count += 1
    elif number_count < a[i]:
        remove_count += number_count
        number_count = 1      
    elif number_count > a[i]:
        remove_count += number_count - a[i]
        number_count = 1
    elif number_count == a[i]:
        number_count = 1   
                
print(remove_count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
lsa=list(set(a))
plus=0
minus=0
for i in range(len(lsa)):
    if a.count(lsa[i])>lsa[i]:
        plus+=a.count(lsa[i])-lsa[i]
    elif a.count(lsa[i])<lsa[i]:
        minus+=lsa[i]-a.count(lsa[i])

if plus==0 or minus==0:
    print(max(plus,minus))
else:
    print(min(plus,minus))