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:
import collections

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

aa = collections.Counter(a).most_common()
print(aa)

for i,j in aa:
    if i > j:
        ans += j
    if i < j:
        ans += j-i
    
print(ans)

Submission status: Wrong Answer

Solution code:
#import itertools
import collections

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

aa = collections.Counter(a).most_common()
#print(aa)

for i,j in aa:
    if i == j:
        continue
    else:
        ans += min(abs(i-j),j)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as c

n = int(input())
s = list(map(int,input().split()))
s = c.Counter(s)
ans = 1
for i in s.items():
    a = i[0]
    b = i[1]
    if b<a:
        ans += b
    else:
        ans += b-a
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

count = 0

for i, j in Counter(a).items():
    print(i, j, j-i, j)
    if j-i < 0:
        count += j
    else:
        count += min(j-i, j)

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}

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

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

ans = 0

for key in dic:
    if dic[key] > key:
        ans += dic[key] - key
    else:
        ans += dic[key]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
d={}
ans=0
if len(A)==1:
    if A[0]==1:
        ans=0
    else:
        ans=1
else:
    for a in A:
        try:
            if d[a]<a:
                d[a]+=1
                ans-=1
            elif d[a]==a:
                ans+=1
        except KeyError:
            d[a]=1
            ans+=(a-1)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
d={}
ans=0
for a in A:
    try:
        if d[a]<a:
            d[a]+=1
            ans-=1
        elif d[a]==a:
            ans+=1
    except KeyError:
        d[a]=1
        ans+=(a-1)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
d={}
ans=0
for a in A:
    try:
        d[a]+=1
    except KeyError:
        d[a]=1
    if d[a]>a:
        ans+=1
        d[a]-=1
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(l)
ans = 0
for dic in c:
    ans += min(abs(c[dic] - 0), abs(dic - c[dic]))

print(ans , flush=True)

Submission status: Wrong Answer

Solution code:
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""


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

ans = 0

for i in range(1,n+1):
    tmp = a.count(i)
    if (tmp-i > 0):
        ans += tmp-i
    elif tmp-i < 0:
        ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""


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

ans = 0
if (a.count(1)-1 > 0): ans += a.count(1)-1 
for i in range(2,n+1):
    tmp = a.count(i)%i
    ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()
    dic = {}
    for i in a:
        dic[i] = dic.get(i,0) + 1
    ans = 0
    for i,k in dic.items():
        if i < k:
            ans += k-1
        elif i > k:
            ans += k
    print(ans)




if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
ans = 0
for i in counterA.keys():
    if i == counterA[i]:
        continue
    ans += min(counterA[i],abs(i-counterA[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

C = Counter(A)
ans = 0

for c in C:
    ans += min(abs(c-C[c]), C[c])

print(ans)

Submission status: Wrong Answer

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

cnt = 0
for i in set(A):
  if i > 10**5:
    break
  I = A.count(i)
  if I == i:
    continue
  elif I > i:
    cnt += I - i
  else:
    cnt += I
  
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
  dic[a[i]] += 1
ans = 0
for key in dic.keys():
  if dic[a[i]] >= a[i]:
    ans += (dic[a[i]] - a[i])
  else:
    ans += dic[a[i]]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
c=0
for i in d:
    if(i!=d[i]):
        c+=min(abs(i-d[i]),d[i])
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
hashmap = defaultdict(int)
for a in A:
  hashmap[a]+=1
ans = 0
for k, v in hashmap.items():
  ans+=min(v,k-v)
print(ans)

Submission status: Wrong Answer

Solution code:
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(abs(k-v),v)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input());a=input().split();d={}
for i in a:
  if i not in d:
    d[i]=min(a.count(i),abs(int(i)-a.count(i)))
print(sum([i for i in d.values()]))

Submission status: Wrong Answer

Solution code:
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)):
    ans+=value1[i]%key1[i]

print(ans)

Submission status: Wrong Answer

Solution code:

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

if len(numbers)==1:
  print(1)
  exit()
counter=0
counter_2=0

for i in range(1000000000):

  if numbers.count(i)==i:
    counter_2+=i
  elif numbers.count(i) != i:
    if numbers.count(i) > i:
      counter+=(numbers.count(i)-i)
    else:
      counter+=numbers.count(i)
    
    counter_2+=numbers.count(i)
  if counter_2==len(numbers):
    break
    
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
X = 0
for x, y in A.items():
  if x <= y and X < x and N - x >= y - x:
    X = x
print(N - X)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
X = 0
for x, y in A.items():
  if x <= y and X < x:
    X = x
print(N - X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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,(k-v if v-k>=0 else 10**9+1)) 
print(sm)

Submission status: Wrong Answer

Solution code:
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,(k-v if k-v>=0 else 10**9+1)) 
print(sm)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
sc=Counter(list(map(int,input().split())))
sm=0
for k,v in sc.items():
  sm+=min(abs(k-v),v) 
print(sm)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
cnt = Counter(a)
ans = 0
for i in cnt.items():
    dif = i[1] - i[0]
    delete = i[1]
    ans += min(dif ,delete)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
cnt = Counter(a)
ans = 0
for i in cnt.items():
    dif = abs(i[0] - i[1])
    delete = i[1]
    ans += min(dif ,delete)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
cnt = Counter(a)
ans = 0
for i in range(len(cnt)):
    dif = abs(cnt.most_common()[i][0] - cnt.most_common()[i][1])
    delete = cnt.most_common()[i][1]
    ans += min(dif ,delete)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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 = abs(k - b[k])
  if tmp > b[k]:
    count += b[k]
  else:
    count += tmp


print(count)

Submission status: Wrong Answer

Solution code:
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():
  count += abs(k - b[k])

print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
c = Counter(readInts())

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
c = Counter(readInts())

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

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import collections
N = int(input())
A=  list(map(int,input().split()))

A.sort()

c = collections.Counter(A)
A_ = list(set(A))
ans = 0
for a in A_:
    ans += min(a-c[a],c[a])

print(ans)

Submission status: Wrong Answer

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

cnt = [0] * 317
res = 0
for v in a:
    if v <= 316:
        cnt[v] += 1
    else:
        res += 1

for i in range(1, 317):
    if cnt[i] < i:
        res += cnt[i]
    elif cnt[i] > i:
        res += cnt[i] - i

print(res)

Submission status: Wrong Answer

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

cnt = [0] * 1001
res = 0
for v in a:
    if v <= 1000:
        cnt[v] += 1
    else:
        res += 1

for i in range(1, 1001):
    if cnt[i] < i:
        res += cnt[i]
    elif cnt[i] > i:
        res += cnt[i] - i

print(res)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): 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)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()
A = l()

aaa = list(set(A))
aaa.sort()
a = max(aaa)

if N == 1:
    print(1)
    sys.exit()

for i in aaa:
    b = A.count(i)
    if b >= i:
        ans += b-i
    else:
        count += b

print(ans+count)

Submission status: Wrong Answer

Solution code:
s = "".join(sorted(input()))
t = "".join(sorted(input(), reverse=True))

if s < t: print("Yes")
else: print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
count = 0
l = len(a)
z = 0
for i in b:
    if i > l:
        count = l-z
        break
    else:
        j = a.count(i)
        if j < i:
            count += j
            z += j
        else:
            count += j-i
            z += j
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
import numpy as np
c = np.array(a)
count = 0
for i in b:
    if i > 10**5:
        j = sum(c>10**5)
        count += j
        break
    else:
        j = a.count(i)
        if j < i:
            count += j
        elif j == i:
            pass
        else:
            k = j - i
            count += k
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
count = 0
z = 0
for i in b:
    if i <= 10**5:    
        j = a.count(i)
        if j < i:
            count += j
            z += j
        else:
            k = j - i
            count += k
            z += j
    else:
        f = len(a) - z
        count += f
        break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
count = 0
z = 0
for i in b:
    if i <= 10**5:    
        j = a.count(i)
        if j < i:
            count += j
            z += j
        else:
            k = j - i
            count += k
            z += j
    else:
        f = len(a) - z
        count += z
        break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
b = set(a)
count = 0
z = 0
for i in b:
    if i <= 10**5:    
        j = a.count(i)
        if j < i:
            count += j
            z += 1
        else:
            k = j - i
            count += k
            z += 1
    else:
        f = len(b) - z
        count += z
        break

print(count)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    a_list = [int(n) for n in input().strip().split()]
    count = Counter(a_list)
    ans = 0
    for k, v in count.items():
        if v == k:
            continue
        elif v > k:
            ans = v - k
        else:
            ans += v
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
# 20200612_yorukatsu_e.py
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
ans = 0
for i,v in C.items():
    # print(i,v)
    if i!=v:
        if i<v:
            ans += v-1
        else:
            ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
# 20200612_yorukatsu_e.py
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
ans = 0
for i,v in C.items():
    print(i,v)
    if i!=v:
        if i<v:
            ans += v-1
        else:
            ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int,input().split()))
p = 0
for i in list(set(ls)):
    a = ls.count(i)
    p += min(a,abs(a-i))
print(p)

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 in range(10**5):
  if i < c[i]:
    ans+=c[i]-i
  elif i > c[i]:
    ans+=c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

import collections

c = collections.Counter(al)

res = 0
for i in range(1,n+1):
    if c[i] ==0:
        pass
    elif c[i] ==i:
        pass
    else:
        if c[i] >i:
            res += c[i]-i
        else :
            res +=c[i]
    
print(res)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int, read().split()))

dic = {}
ans = 0

for i in range(n):
  ans += 1
  try:
    dic[a[i]] += 1
    if dic[a[i]] == a[i]:
      ans -= a[i]
  except KeyError:
    dic[a[i]] = 1
    if dic[a[i]] == a[i]:
      ans -= a[i]

print(dic)
print(ans)

Submission status: Wrong Answer

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

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

b = collections.Counter(a)

ans = 0

for k,v in b.items():
    ans += min(v,abs(k-v))
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
al = list(map(int,input().split()))
C = Counter(al)

ans = 0
for i in C.keys():
    if i in C:
        if C[i] == i:
            continue
        else:
            ans += min(abs(C[i] - i),C[i])


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
n=l()[0]
A=l()
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=0
    d[A[i]]+=1
ans=0
for k in d:
    if(d[k]<k):
        ans+=k
    else:
        ans+=(d[k]-k)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

ac = collections.Counter(a)
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in a:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1
ans = 0
for k, v in dic.items():
    if k > v:
        ans += v
    elif k < v:
        ans += k - v

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
A = a.sort()
array = list(set(a))
array.sort()
sum = 0
n = 0
for i in range(len(array)):
    cnt = 0
    for j in range(n,len(a)):
        if array[i] == a[j]:
            cnt += 1
        else:
            break
    n += cnt
    print(cnt,array[i])
    if cnt >= array[i]:
        sum += cnt - array[i]
    else:
        sum += cnt
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
array = list(set(a))
sum = 0
n = 0
for i in range(len(array)):
    cnt = 0
    for j in range(n,len(a)):
        if array[i] == a[j]:
            cnt += 1
        else:
            break
    n += cnt
    if cnt >= array[i]:
        sum += cnt - array[i]
    else:
        sum += cnt
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
A = Counter(a)
ans = 0
for x in A:
    ans += min(abs(x-A[x]), A[x])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

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

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

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

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


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

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

    ret = 0
    for k in A:
        v = A[k]
        ret += min(abs(k-v), v)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
l = collections.Counter(a)
#print(l)
v = list(l.keys())
#print(v)
ans = 0
for i in v:
    ans += min(abs(l.get(i)-i),l.get(i))
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools

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

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

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

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


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

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

count = Counter(a)
#print(count)
unique = list(set(a))
print(unique)

ans = 0
for uni in unique:
    #print(count[3], uni)
    if count[uni] < uni:
        continue
    else:
        ans += uni

print(len(a) - ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

count = Counter(a)
#print(count)
unique = list(set(a))
#print(a)

ans = 0
for uni in unique:
    #print(count[3], uni)
    if count[uni] < uni:
        break
    else:
        ans += uni

print(len(a) - ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
if not N == 1:
    counter = defaultdict(lambda: 0)
    for e in list(map(int, input().split())):
        counter[e] += 1
    answer = 0
    # この行がバグの原因
    for i in range(1, N+1):
        ball_count = counter[i]
        if i > ball_count:
            answer += ball_count
        elif i < ball_count:
            answer += ball_count - i
    print(answer)
else:
    if not 1 == int(input()):
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
if not N == 1:
    counter = defaultdict(lambda: 0)
    for e in list(map(int, input().split())):
        counter[int(e)-1] += 1

    answer = 0
    for i in range(N):
        ball = counter[i]
        if not i+1 == ball:
            if i+1 > ball:
                answer += ball
            elif i+1 < ball:
                answer += ball - (i+1)
    print(answer)
else:
    if not 1 == int(input()):
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
ans=0
for k, v in d.items():
    if v != k:
        ans+=min(v, abs(k-v))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from collections import Counter

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


if __name__ == '__main__':
    main()