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 math

line1 = int(input())
line2 = str(input()).split(" ")
for index in range(len(line2)):
    line2[index] = int(line2[index])

keepTrack = dict()
keys = []
for element in line2:
    if element in keys:
        keepTrack[element] += 1
    else:
        keepTrack[element] = 1
        keys.append(element)
sum = 0
for key in keys:
    ##sum += abs()
    sum += min(abs(key - keepTrack[key]), keepTrack[key])
print(sum)

Submission status: Wrong Answer

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

if len(seq) == 1:
  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: Wrong Answer

Solution code:
def main():
    n = int(input())
    li = list(map(int, input().split()))
    inds = []
    for i in range(len(li)):
        tmp = [i]
        if li[i] > len(li[i:]):
            break
        for j in range(i + 1, len(li)):
            if li[i] == li[j]:
                tmp.append(j)
            if len(tmp) > li[i]:
                tmp = []
                break
        if li[i] == len(tmp):
            inds.extend(tmp)
    print(n - len(inds))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    li = list(map(int, input().split()))
    inds = []
    for i in range(len(li)):
        tmp = [i]
        if li[i] > len(li[i:]):
            break
        for j in range(i + 1, len(li)):
            if li[i] == li[j]:
                tmp.append(j)
            if len(tmp) > li[i]:
                tmp = []
                break
        if li[i] == len(tmp):
            inds.extend(tmp)
    print(inds)
    print(n - len(inds))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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():
        result += min(value, abs(value - key))
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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):
  ans += min(abs(count[i] - i), count[i])
print(ans+tmp)

Submission status: Wrong Answer

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] > 0:
    ans += min(abs(count[i] - i), count[i])
print(ans+tmp)

Submission status: Wrong Answer

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():
    cnt += min(value, abs(key - value))

print(cnt)

Submission status: Wrong Answer

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:
    ans+=max(0,d[x]-x)
print(ans)

Submission status: Wrong Answer

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

delete = 0

for i in range(n):
  if a.count(i) < i:
    delete += a.count(i)
  elif a.count(i) > i:
    delete += a.count(i) - i
    
print(delete)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

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

cnt_dic = Counter(a_list)

cnt=0
for i,value in cnt_dic.items():
    if i == value:
        continue
    else:
        cnt += min( abs(i- value), value )

print(cnt)

Submission status: Wrong Answer

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


ans = 0
A = Counter(a)

for i in A.keys():
    if i != A[i]:
        ans += min(A[i], abs(A[i]-i))

print(ans)

Submission status: Wrong Answer

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


ans = 0
A = Counter(a)

for i in A.keys():
    if i != A[i]:
        ans += min(A[i], abs(i-A[i]))

print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for k, c in ac.items():
  diff = abs(c - k)
  if diff < c:
    ans += diff
  else:
    ans += c

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n:
    arr = list(map(int, input().split()))
    t = 0
    for i in set(arr):
        t += i
    print(abs(n-t))
else:
    print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
t = 0
for i in set(arr):
    t += i
print(abs(n-t))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def Good_Sequence(n , al):

    count = {}
    ans = 0

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

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

    return ans

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def Good_Sequence(n , al):

    count = {}
    ans = 0

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

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

    return ans

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import collections

A_count = collections.Counter(A)


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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a = list(Counter(a).items())
result = 0
for number, how_many in a:
    result += min(abs(how_many-number), how_many)
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for i in range(len(b)):
    if a.count(b[i]) != b[i]:
        ans += min(abs(a.count(b[i]) - b[i]), a.count(b[i]))
print(ans)

Submission status: Wrong Answer

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

value = 0
cnt = 0
pos = 0

while (pos < N):
    
    cur_value = sequence[pos]
    tmp_cnt = 1
    
    while (pos + 1 < N):
        if (cur_value == sequence[pos + 1]):
            pos += 1
            tmp_cnt += 1
        else:
            pos += 1
            break
    
    if (cur_value > tmp_cnt):
        cnt += tmp_cnt
    
    else:
        cnt += tmp_cnt - cur_value
    
    
    if (pos == N - 1):
        break

print(cnt)

Submission status: Wrong Answer

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

for key,value in b.items():
    ans += abs(key-value)

ans = min(ans,n)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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


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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
B = set(A)
t = 0
s = 0
m = 0
for i in B:
    s = 0
    for j in A[m:]:
        if j == i:
            s += 1
        elif j > i:
            break
        else:
            continue
    m += s
    if s >= i:
        t += s - i
    else:
        t += s
print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
adict=dict()
for i in range(n):
  if adict.get(a[i])!=None:
    adict[a[i]]+=1
  else:
    adict[a[i]] = 1
cnt=0

for i in range(len(adict)):
  if adict[a[i]]>=a[i]:
    cnt+=(adict[a[i]]-a[i])
  else:
    cnt+=adict[a[i]]
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt=0
set_alist=list(set(a))
for i in range(len(set_alist)):
  acount=a.count(set_alist[i])
  if acount>set_alist[i]:
    cnt+=acount-set_alist[i]
  else:
    cnt+=acount
  
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
adict=dict()
for i in range(n):
  if adict.get(a[i])!=None:
    adict[a[i]]+=1
  else:
    adict[a[i]] = 1
cnt=0

for i in range(len(adict)):
  if adict[a[i]]>a[i]:
    cnt+=(adict[a[i]]-a[i])
  elif adict[a[i]]<a[i]:
    cnt+=adict[a[i]]
print(cnt)

Submission status: Wrong Answer

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

for i in fila:
    if i not in num:
        num.append(i)
perdas = 0
for i in num:
    cont = 0
    for j in fila:
        if i == j:
            cont += 1
    if i != cont:
        if cont != 1:
            perdas = cont - i
        else:
            perdas += 1
        
    if perdas < 0:
        perdas = perdas*(-1)
print(perdas)

Submission status: Wrong Answer

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

b = [0 for _ in range(n+1)]

ans = 0
for i in range(n):
    if a[i] > n:
        ans += 1
    else:
        b[a[i]] += 1 

print(b)

for i in range(n+1):
    if b[i] > i: ans += b[i] - i
    if b[i] < i: ans += b[i]

print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

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

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

Submission status: Wrong Answer

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

ans=0
lastnum=a[0]
cnt=1
tmp=0
for num in a[1:]:
    if num==lastnum:
        cnt+=1
    else:
        ans+=min(cnt,abs(cnt-lastnum))
        cnt=1
    tmp=lastnum
    lastnum=num

ans+=min(cnt,abs(cnt-tmp))
print(ans)

Submission status: Wrong Answer

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

ans=0
lastnum=a[0]
cnt=1
for num in a[1:]:
    if num==lastnum:
        cnt+=1
    else:
        ans+=min(cnt,abs(cnt-lastnum))
        cnt=1
    lastnum=num
ans+=min(cnt,abs(cnt-lastnum))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
counter = 0
AN = set(A)
A = np.array(A)

for i in AN:
    num = len(A[A < i])
    counter += abs(num - i)

print(counter)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
a=list(map(int,input().split()))
a_counter=collections.Counter(a)
answer = 0
# print(a_counter)
# print(a_counter[0])
# print(a_counter[1])
# print(a_counter[2])
# print(a_counter[3])
for i in a_counter:
    # print(i)
    # print(i == a_counter[i])
    if i != a_counter[i]:
        answer += min(abs(i-a_counter[i]),a_counter[i])

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
dic = {}
count = 0

for i in range(n):
  dic.setdefault(l[i],0)
  dic[l[i]] += 1
print(dic)
for x,y in dic.items():
  if x <= y:
    count += y - x
  else:
    count += y
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
L = list(set(l))
count = 0
for x in L:
  num = l.count(x)
  if num > x:
    count += num - x
  else:
    count += x - num
print(count)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
cntA = collections.Counter(list(map(int, input().split())))
ans = 0
for num in cntA:
    if num <= cntA[num]:
        ans += cntA[num] - num
    else:
        ans += min(cntA[num], num - cntA[num])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
ans = 0
for ai in d:
  ans += max(0, d[ai] - ai)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=set()
ans=0
d={}
cnt=0
for i in range(n-1):
    cnt+=1
    if i==n-2 and a[i]==a[i+1]:
        cnt+=1
        d[a[i]]=cnt
        break    
    if a[i]!=a[i+1]:
        d[a[i]]=cnt
        cnt=0
for i in d.keys():
    if d[i]>=i:
        ans+=d[i]-i
    else:
        ans+=d[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in A:
  if i in D:
    D[i] += 1
  else:
    D[i] = 1
p = 0
for i in D:
  if D[i] >= i:
    p += i - D[i]
  else:
    p += D[i]
print(p)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
ans = 0
for it in c.items():
    if it[0] <= it[1]:
        ans += (it[1]-it[0])
    else:
        ans += it[0]
print (ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
ans = 0
for it in c.items():
    if it[0] < it[1]:
        ans += (it[1]-it[0])
    else:
        ans += it[0]
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,m in c.items():
    ans += min(abs(m-i), m)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(0)
num = a[0]
cnt = 1
ans = 0
for i in range(1, n + 1):
    if a[i] == num:
        cnt += 1
    else:
        ans += abs(min(num - cnt, cnt))
        num = a[i]
        cnt = 1
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 key, val in B.items():
    if val >= key:
        ans += val - key
    else:
        ans += key

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int , input().split()))
B = []
for i in range(1,N+1):
    S = A.count(i)
    B.append((int(i),int(S)))

#print(B)


ans = 0
for i in range(N):
    if B[i][0] != B[i][1] and B[i][1] != 0:
        if B[i][0] < B[i][1]:
            ans += B[i][1] - B[i][0]
        elif B[i][0] > B[i][1]:
            ans += B[i][1]
if N == 1:
    print('1')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
i = 0
ans = 0
cnt = 1
if N == 1:
    print(1)
    exit()

while i+1 < N:
    if A[i] == A[i+1]:
        cnt += 1
        if i+1 == N-1:
            ans += cnt if A[i] > cnt else cnt - A[i]
    else:
        ans += cnt if A[i] > cnt else cnt - A[i]
        cnt = 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(A) #要素と出現回数の辞書
print(c)

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

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
List=sorted(list(map(int, input().split())))

c = collections.Counter(List) #要素と出現回数の辞書
value, count = zip(*c.most_common())


newList=[]

for i in range(len(value)):
    if N-len(newList)>=value[i] and count[i]>=value[i]:
        for j in range(value[i]):
            newList.append(value[i])
    else:
        continue

print(newList)

Ans=len(List)-len(newList)
print(Ans)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
List=sorted(list(map(int, input().split())))

c = collections.Counter(List) #要素と出現回数の辞書
value, count = zip(*c.most_common())


newList=[]

for i in range(len(value)):
    if N-len(newList)>=value[i] and count[i]>=value[i]:
        for j in range(value[i]):
            newList.append(value[i])
    else:
        break

print(newList)

Ans=len(List)-len(newList)
print(Ans)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
List=sorted(list(map(int, input().split())))

c = collections.Counter(List) #要素と出現回数の辞書
value, count = zip(*c.most_common())
#print(sorted(value)) 
#print(sorted(count)) 

value=sorted(value)
count=sorted(count)

newList=[]

for i in range(len(value)):
    if N-len(newList)>=value[i] and count[i]>=value[i]:
        for j in range(value[i]):
            newList.append(value[i])
    else:
        break

#print(newList)

Ans=len(List)-len(newList)
print(Ans)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
List=sorted(list(map(int, input().split())))

c = collections.Counter(List) #要素と出現回数の辞書
value, count = zip(*c.most_common())
#print(sorted(value)) 
#print(sorted(count)) 

newList=[]

for i in sorted(value):
    if N-len(newList)>=i:
        for j in range(i):
            newList.append(i)
    else:
        break

#print(newList)

Ans=len(List)-len(newList)
print(Ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

C = dict(collections.Counter(A))

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=set(a)
ans=0
for i in s:
  if a.count(i)!=i:
    ans+=a.count(i)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A = collections.Counter(A)

    cnt = 0
    for a in A:
        if A[a] != a:
            if abs(A[a] - a) < A[a]:
                cnt += abs(A[a] - a)
            else:
                cnt += A[a]

    print(cnt)


main()

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
removal=0
B=set(A)
for i in B:
  m=bisect.bisect_right(A,i)
  if m-i<0:
    removal+=m
  else:
    removal+=m-i
  A.remove(i)
print(removal)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
ans = 0
for key,count in D.items():
    ans += min(abs(key-count),count)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = (10001)*[0]
z = 0

for a in A:
  if 10001<=a:
    z+=1
  else:
    B[a]+=1

for i in range(10001):
  if B[i]<i:
    z+=B[i]
  elif i<B[i]:
    z+=B[i]-i

print(z)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = (10001)*[0]
z = 0

for a in A:
  if 10000<=a:
    z+=1
  else:
    B[a]+=1

for i in range(10001):
  if B[i]<i:
    z+=B[i]
  elif i<B[i]:
    z+=B[i]-i

print(z)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
b = Counter(tuple(map(int, input().split())))
counter = 0
for item in b.items():
    if item[1] >= item[0]:
        counter += item[1] - item[0]
    else:
        counter += item[0] - item[1]
print(counter)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
b = Counter(tuple(map(int, input().split())))
counter = 0
for item in b.items():
    counter += item[1] - item[0]
print(counter)

Submission status: Wrong Answer

Solution code:
#ABC082 C - Good Sequence
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict
N = ni()
A = nl()
D = defaultdict(int)
for a in A:
    D[a] += 1

ans = 0

for d in D:
    ans += min(abs(D[d]-d),D[d])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c,ans=0,0
for x in b:
  c=a.count(x)
  if c>=int(x):
    ans+=int(x)
  else:
    ans+=c
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 0
x = 10**5
count_list = [0]*(x+1)

for i in a:
    if i > x:
        ans += 1
    else:
        if count_list[i] >= i:
            ans += 1
        else:
            count_list[i] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_lst  = sorted(list(map(int, input().split())))
                                                                                                                                                                                                                                              
idx = 0
count = 0
for i in range(N):
    try:
        a = A_lst[idx]
    except IndexError:
        break
    if a > N:
      break
    a_count = A_lst.count(a)
    if a_count < a:
        count += a_count
    elif a_count > a:
        count += a_count - a
    idx += a_count
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split(" ")))
save = {}
save2 = {}
res = 0
for i in A:
  if i in save:
  	save[i]=i
  else:
    save[i]= 1
    
for j in A:
  save[j]-=1

for x in save.keys():
  if save[x] > 0:
    res+=save[x]
print(res)

Submission status: Wrong Answer

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

count = 0
for i in set(A_lst):
    if i > N:
      break
    j = A_lst.count(i)
    if (i-j) > 0:
        count += j
    elif (i-j) < 0:
        count += j-i
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_lst  = list(map(int, input().split()))
A_set = set(A_lst)
                                                                                                                                                                                                                                              
count = 0
for a in A_set:
    ac = A_lst.count(a)
    if ac != a:
        count += ac - a
print(abs(count))

Submission status: Wrong Answer

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

ans = 0
#辞書型でデータを管理
dict = {}
for i in range(n):
    if a[i] not in dict:
        dict[a[i]] = 1
    else:
        dict[a[i]] += 1
print(dict.keys())
for i in dict.keys():
    if i < dict[i]:
        #多い場合は減らすのが確定
        ans += dict[i] - i
    elif i > dict[i]:
        ans += dict[i]
print(ans)

Submission status: Wrong Answer

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

ans = 0
#辞書型でデータを管理
dict = {}
for i in range(n):
    if a[i] not in dict:
        dict[a[i]] = 1
    else:
        dict[a[i]] += 1
for i in dict.keys():
    if i < dict[i]:
        #多い場合は減らすのが確定
        ans += dict[i] - i
    elif i > dict[i]:
        #減らしたほうが早いのか、増やしたほうが早いのか？
        ans += min(dict[i], i - dict[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=[int(i) for i in input().split()]
x=collections.Counter(a)
ans=0
for i in x:
    if x[i]!=i:
        ans+=x[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N=int(input())
a=[int(item) for item in input().split()]

dd=defaultdict(int)

for item in a:
  dd[item]+=1


ans=0
for item in set(a):
  if dd[item]>item:
    ans+=dd[item]-item
  else:
    ans+=dd[item]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N=int(input())
a=[int(item) for item in input().split()]

dd=defaultdict(int)

for item in a:
  dd[item]+=1

ans=0
for item in set(a):
  ans+=min(abs(dd[item]-item),dd[item])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * 200000
ans = 0
for i in range(N):
	if A[i] < 200000:
		B[A[i]] += 1
	else:
		ans += 1
for i in range(200000):
	ans += min(B[i], (i - B[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * 200000
ans = 0
for i in range(N):
	if A[i] < 200000:
		B[A[i]] += 1
	else:
		ans += 1
for i in range(200000):
	ans += min(B[i], abs(i - B[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
dic={}
for e in ls:
  if (e in dic):
    dic[e]+=1
  else:
    dic[e]=1
ans=0
for k,v in dic.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()))
list_cnt = [0] * (10 ** 5 + 1)

ans = 0
for a in A:
    if a > 10 ** 5:
        ans += 1
    else:
        list_cnt[a-1] += 1

for i in range(N):
    if list_cnt[i] >= i + 1:
        ans += (list_cnt[i] - i - 1)
    else:
        ans += list_cnt[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(lst)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s_a = set(a)
c_min = n
b = True
for i in s_a:
    if a.count(i) - i != 0:
        c_min += min(abs(a.count(i)-i), a.count(i))
        b = False
    else:
        pass

if b == True:
    c_min = 0

print(c_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s_a = set(a)
c_min = n
b = True
for i in s_a:
    if a.count(i) - i != 0:
        c_min = min(abs(a.count(i)-i), a.count(i))
        b = False
    else:
        pass

if b == True:
    c_min = 0

print(c_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s_a = set(a)
c_min = n
b = True
for i in s_a:
    if a.count(i) - i != 0:
        c_min = abs(a.count(i) - i)
        b = False
    else:
        pass

if b == True:
    c_min = 0

print(c_min)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in a:
  if i<=a.count(i):
    cnt+=(a.count(i)-i)
  else:
    cnt+=a.count(i)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
keys=c.keys()
vals=c.values()
ans=0
for key, val in zip(keys,vals):
    ans+=min(abs(val-key),val)
print(ans)

Submission status: Wrong Answer

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

z=a[0]
c=0
ans=0
for i in range(n):
    if z==a[i]:
        c+=1
    else:
        if z==c:
            continue
        elif z<c:
            ans+=c-z
        elif z>c:
            ans+=c
        z=a[i]
        c=0
p=a.count(a[-1])
if p<a[-1]:
    ans+=p
elif p>a[-1]:
    ans+=p-a[-1]

print(ans)

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:
    aCount = aList.count(a)
    if aCount > a:
        aSum += aCount - a
    if aCount < a:
        aSum += aCount
    aLen -= aCount
    if a > aLen:
        aSum += aLen
        break
print(aSum)