Problem:


Score : 300 points

Problem Statement

You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.

Here, an sequence b is a good sequence when the following condition holds true:

For each element x in b, the value x occurs exactly x times in b.

For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.

Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Constraints

1 \leq N \leq 10^5

a_i is an integer.

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of elements that needs to be removed so that a will be a good sequence.

Sample Input 1

4
3 3 3 3

Sample Output 1

1

We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.

Sample Input 2

5
2 4 1 4 2

Sample Output 2

2

We can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence.

Sample Input 3

6
1 2 2 3 3 3

Sample Output 3

0

Sample Input 4

1
1000000000

Sample Output 4

1

Remove one occurrence of 10^9. Then, () is a good sequence.

Sample Input 5

8
2 7 1 8 2 8 1 8

Sample Output 5

5



Sample input:
4
3 3 3 3


Sample output:
1

Submission status: Accepted

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

a.sort()

good_val = 0
total_cnt = 0
tmp_cnt = 0
over = 0
for i in range(n):
  if good_val == 0:
    good_val = a[i]

  if a[i] == good_val:
    tmp_cnt += 1
    if over == 0 and tmp_cnt == good_val:
      tmp_cnt = 0
      over = 1
    if i == n - 1:
      total_cnt += tmp_cnt
  else:
    total_cnt += tmp_cnt
    good_val = a[i]
    tmp_cnt = 1
    over = 0
    if i == n - 1:
      total_cnt += tmp_cnt

print(total_cnt)

Submission status: Accepted

Solution code:
N, = map(int, input().split())
A = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
for a in A:
    d[a] += 1
r = 0
for a in d:
    if a > d[a]:
        r += d[a]
    else:
        r += d[a]-a
print(r)

Submission status: Accepted

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

from collections import Counter
C = 0
mycounter = Counter(A)
for i, v in mycounter.items():
  if int(i) < int (v):
    C += int (v) - int(i)
  elif int(i) > int(v):
    C += int(v)

print(C)

Submission status: Accepted

Solution code:
from itertools import groupby

def main():
    N=int(input())
    A=list(map(int,input().split()))
    A.sort()
    X=groupby(A)
    s=0
    for key,group in X:
        t=len(list(group))
        if int(key)>t:
            s+=t
        else:
            s+=t-int(key)
    print(s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split( )))
from collections import Counter 
c = Counter(a)
ans = 0
for ci in c:
    if c[ci]>=ci:
        ans += c[ci]-ci
    else:
        ans += c[ci]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    M = Counter(A)
    ans = 0
    for k, v in M.items():
        if k == v:
            continue
        if k < v:
            ans += v-k
        else:
            ans += v
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

a = Counter(A)

con = 0

for num in a.keys():
  time = a[num]
  if time > num:
    con += (time - num)
  elif num > time:
    con += time

print(con)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)
ans = 0
for x in c.keys():
    if c[x] >= x:
        ans += c[x] - x
    else:
        ans += c[x]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
n=int(input())
a=[int(i) for i in input().split()]
d=dd(int)
for i in a:
    d[i]+=1

ans=0
for i in d.keys():
    if(d[i]>=i):
        ans+=(abs(d[i]-i))
    else:
        ans+=d[i]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections


def solve(N: int, a):
    c = collections.Counter(a)
    z = 0
    for k, v in c.items():
        if v - k < 0:
            z += v
        else:
            z += v - k
    print(z)


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    cc = Counter(aa)
    ans = 0
    for k, v in cc.items():
        if k < v: ans += v - k
        if k > v: ans += v
    print(ans)

main()

Submission status: Accepted

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

cn = 1
for i in range(n):
    if(a[i]==a[i+1]):
        cn += 1
    else:
        b.append((a[i],cn))
        cn = 1
        
b.sort(key = lambda x : (x[0],x[1]))
#print(b)
sn = 0

for i in range(len(b)):
    if(b[i][1]-b[i][0]<0):
        sn += b[i][1]
    elif(b[i][1]-b[i][0]>0):
        sn += b[i][1]-b[i][0]
        
print(sn)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)#n
c=list(set(b))
c.sort()
kosuu_list=[]
kosuu=1
for i in range(len(b)-1):
    #kosuu=0
    #print(b[i])
    if b[i]==b[i+1]:
        kosuu+=1
    else:
        kosuu_list.append(kosuu)
        kosuu=1
kosuu_list.append(b.count(b[-1]))
#print(kosuu_list)
count=0
#print(c)
for i in range(len(c)):
    if kosuu_list[i]==c[i]:
        count+=0
    elif kosuu_list[i]>=c[i]:
        count+=kosuu_list[i]-c[i]
    else:
        count+=kosuu_list[i]
print(count)

Submission status: Accepted

Solution code:
from collections import Counter


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

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

for i in range(N):
    if not A[i] in dic:
        dic[A[i]] = 0
    dic[A[i]] += 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC087C
import sys
import math

n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

numlist={}

for i in range(0,n):
	if(hoge[i] in numlist):
		numlist[hoge[i]]+=1
	else:
		numlist[hoge[i]]=1

total=0

for i in numlist:
	if(i in numlist):
		#print("{} {}".format(i,numlist[i]))
		if(i>numlist[i]):
			total+=numlist[i]
		else:
			total+=numlist[i]-i


#print(hoge)
#print(numlist)
print(total)

Submission status: Accepted

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

counts = {}
for a in A:
    if a not in counts:
        counts[a] = 1
    else:
        counts[a] += 1
    
ans = 0
for key,val in counts.items():
    if val > key:
        ans += val - key
    if val < key:
        ans += val

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
dic = defaultdict(int)
for a in A:
    dic[a] += 1

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

Submission status: Accepted

Solution code:
# ABC082C - Good Sequence (ARC087C)
import sys

input = sys.stdin.readline

from collections import Counter


def main():
    n = int(input())
    cnt = Counter(list(map(int, input().rstrip().split())))
    ans = 0
    for i, j in cnt.items():
        if i > j:
            ans += j
        elif i < j:
            ans += j - i
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ARC087C - Good Sequence (ABC082C)
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = {}
    for i in lst:
        if i not in cnt:
            cnt[i] = 0
        cnt[i] += 1
    ans = 0
    for i, j in cnt.items():
        if i > j:
            ans += j
        elif i < j:
            ans += j - i
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

D = {}

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

ans = 0

for a in D :
    if D[a] < a :
        ans += D[a]
    else :
        ans += (D[a] - a)

print(ans)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a_set = set(a)
ans = 0

from collections import Counter
x_count = Counter(a)

for i in a_set:
    if i != x_count[i]:
        if i < x_count[i]:
            ans += abs(x_count[i] - i)
        elif i > x_count[i]:
            ans += x_count[i]
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=list(map(int,input().split(' ')))
counter=collections.Counter(A)
ans=0
for key, val in counter.items():
  ans += val if val < key else val-key
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
As = map(int, input().split())

counts = defaultdict(int)
for a in As:
    counts[a] += 1

total = 0
for n, c in counts.items():
    if n < c:
        total += c - n
    elif n > c:
        total += c

print(total)

Submission status: Accepted

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

dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
    
ans = 0
for k in dic:
    if dic[k]>k:
        ans += dic[k]-k
    elif dic[k]<k:
        ans += dic[k]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(_) for _ in input().split()]
List = [0]*(10**5+1)
ans = 0

for i in a:
    if i > 10**5:
        ans += 1
    else:
        List[i] += 1

for i in range(1, 10**5+1):
    if List[i] >= i:
        ans += List[i] - i
    else:
        ans += List[i]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=tuple([int(i) for i in input().split()])
cnt=dict(Counter(a))
ans=0
for i,j in zip(cnt.keys(),cnt.values()):
    if i>j:
        ans+=j
    elif i!=j:
        ans+=j-i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n= int(input())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
a2 = list(set(a))
ans = 0
for i in a2:
  tmp = c[i]
  if tmp <i:
   ans += tmp
  else:
   ans += (tmp-i)
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split()))).most_common()
ans = 0
for i, j in a:
    if i > j:
        ans += j
    if i < j:
        ans += j - i
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split()))).most_common()
ans = 0
for i, j in a:
    if i > j:
        ans += j
    if i < j:
        ans += j - i
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(A)

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

print(ans)

Submission status: Accepted

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

c = collections.Counter(a)
res = 0
for k, v in c.items():
  if k > v:
    res += v
  elif k < v:
    res += v - k
print res

Submission status: Accepted

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

c = collections.Counter(a)
res = 0
for k, v in c.items():
  if k > v:
    res += v
  elif k < v:
    res += v - k
print res

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = input().split(' ')
counter_A = collections.Counter(A)

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

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Ca=dict(Counter(A))
Dk=Ca.keys()
a=0
for i in Dk:
    if i>Ca[i]:
        a+=Ca[i]
    elif i<Ca[i]:
        a+=Ca[i]-i
print(a)

Submission status: Accepted

Solution code:
import collections 
def inpl(): return [int(i) for i in input().split()]

N= int(input())
A = collections.Counter(inpl())
ans = 0
for i in A.keys():
    if i > A[i]:
        ans += A[i]
    else:
        ans += A[i] - i
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
nums = getlist()

kazu = defaultdict(int)
for i in nums:
    kazu[i] += 1

ans = 0
for x in kazu.keys():
    if kazu[x] >= x:
        ans += kazu[x] - x
    else:
        ans += kazu[x]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as C

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

res = 0
d = (dict(c))
for k in list(c):
    #print(k,d[k])
    if d[k]<k:
        res += d[k]
    else:
        res += d[k] - k
print(res)

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
cou = {}
for i in range(n):
    if lis[i] in cou:
        cou[lis[i]] += 1
    else:
        cou[lis[i]] = 1
ans = 0
for i in cou:
    if cou[i] < i:
        ans += cou[i]
    else:
        ans += abs(cou[i] -i)
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

cnt = Counter(a)

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

Submission status: Accepted

Solution code:
N=int(input().strip())
a=list(map(int, input().split()))
nlis={}

for i in range(N):
    if (a[i] in nlis)==False:
        nlis[a[i]]=1
    else:
        nlis[a[i]]+=1
ans=0
for i in nlis:
    if nlis[i]<i:
        ans+=nlis[i]
    else:
        ans+=abs(nlis[i]-i)
    #print(ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().strip().split()))
a.sort()
i = 0
j = 1
ans = 0

for i in range(N-1):
	if a[i] == a[i+1]:
		j += 1
	else:
		if j >= a[i]:
			ans += j - a[i]
		else:
			ans += j
		j = 1
if a[N-1] != a[N-2]:
	if a[N-1] != 1:
		ans += 1
else:
	if j >= a[i]:
		ans += j - a[i]
	else:
		ans += j
print(ans)

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=[int(a) for a in input().split()]
c=collections.Counter(A)
ans=0
for k,v in c.items():
  if k>v:
    ans+=v
  else:
    ans+=v-k
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import collections

# 1行目は破棄
input()

# 2行目を読み込み、リストに変換
a = map(int, input().split())

# 結果保持用の変数を宣言
count_res = 0

# それぞれの個数をカウント
count = collections.Counter(a)

#カウンタの要素ごとに繰り返し
for k, v in count.items():

## 数値>個数の数値→すべて削除なので一時変数にすべて加算
    if (k>v) :
        count_res += v

## 数値=個数の数値→変化なし

## 数値<個数の数値→超過分だけ削除するので個数-数値を一時変数に加算
    elif (k<v) :
        count_res += (v-k)
        
#結果表示
print(count_res)

Submission status: Accepted

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

D = {}

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

ret = 0
for k in D.keys():
    if D[k] > k:
        ret += D[k] - k
    elif D[k] < k:
        ret += D[k]

print(ret)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
d = collections.Counter(a)
c = 0
for x in d:
  c += max(d[x]-x,0) + d[x]*(d[x]<x)
print(c)

Submission status: Accepted

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

L = []

c = 1

for i in range(1, N):
	if a[i - 1] == a[i]:
		c += 1

	else:
		L.append([c, a[i - 1]])
		c = 1

L.append([c, a[-1]])

ans = 0
for i in range(len(L)):
	if L[i][0] >= L[i][1]:
		ans += L[i][0] - L[i][1]
	else:
		ans += L[i][0]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

d = {}
ret = 0
for x in input().split():
    a = int(x)
    if a not in d:
        d[a] = 0

    if d[a] == a:
        ret += 1
    else:
        d[a] += 1

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

Submission status: Accepted

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

ret = 0
cnt = 0
n = 0

for i in range(N):
    if n == 0:
        cnt += 1
        n = A[i]
        continue

    if n != A[i]:
        ret += cnt if cnt < n else cnt - n
        n = A[i]
        cnt = 1
    else:
        cnt += 1

if cnt != n:
    ret += cnt if cnt < n else cnt - n

print(ret)

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
D=dict()
for i in range(N):
    if A[i] in D:
        D[A[i]]+=1
    else:
        D[A[i]]=1
ans=0
for key in D:
    if D[key]<key:
        ans+=D[key]
    else:
        ans+=D[key]-key
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
ans=0
for d,s in dd.items():
    #print(d,s)
    if s>=d:
        ans+=s-d
    else:
        ans+=s
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

b = {}

for i in a:
    if i in b:
        b[i] += 1
    else:
        b[i] = 1
ans = 0
for i in b:
    if i < b[i]:
        ans += b[i]-i
    elif i > b[i]:
        ans += b[i]
print(ans)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
a = reads()
freq = defaultdict(lambda: 0)
for x in a:
  freq[x] += 1
ans = sum(v - k if v >= k else v for k, v in freq.items())
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

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

dic = {}

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

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

Submission status: Accepted

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

a.sort()

count = 0

while a:
    k = a.pop(-1)
    k_count = 1
    while (len(a) > 0) and (a[-1] == k):
        a.pop(-1)
        k_count += 1
    if k_count < k:
        count += k_count
    else:
        count += k_count - k
print(count)

Submission status: Accepted

Solution code:
from pprint import pprint
n=int(input())
a=[int(i) for i in input().split()]
d={}
cnt=0
for i in a:
    if str(i) not in d:
        d[str(i)]=1
    else:
        d[str(i)]+=1
for i in d:
    if int(i)>d[i]:
        cnt+=d[i]
    else:
        if int(i)<d[i]:
            cnt+=d[i]-int(i)
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())

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

C = defaultdict(int)

for a in A: C[a] += 1
    
ans = 0
for k in C:
    if C[k] < k:
        ans += C[k]
    elif C[k] > k:
        ans += C[k]-k
        
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

n = int(raw_input().strip())
ais = map(int, raw_input().strip().split())

coll = dd(int)
for ai in ais:
    coll[ai] += 1

total = 0
for key, value in coll.iteritems():
    if value < key:
        total += value
    else:
        total += value - key

print total

Submission status: Accepted

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

s=[0 for i in range(n+1)]
count=0

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

for i in range(n+1):
  if s[i]>=i:
    count+=s[i]-i
  else:
    count+=s[i]
   
print(count)

Submission status: Accepted

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

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

num = {}
for x in a:
    if x in num:
        num[x] += 1
    else:
        num[x] = 1

res = 0
for x in num:
    if num[x] >= x:
        res += num[x] - x
    else:
        res += num[x]

print(res)

Submission status: Accepted

Solution code:
import collections
a = int(input())
ppp = [0]
ppp = list(map(int,input().split()))
count = 0             
data = collections.Counter(ppp)
aaa = 0
for k, v in data.items():
    if int(k) > int(v):
        aaa = v
        count += aaa
    elif int(k) < int(v):
        aaa = v-k
        count += aaa
    
print(count)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
data=collections.Counter(a)
count=0
for i,j in data.items():
    if i<j:
        count+=j-i
    elif j<i:
        count+=j
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
nums=list(map(int,input().split(" ")))
ap={}
co=0 
for i in nums:
	if i in ap:
		ap[i]+=1
	else:
		ap[i]=1

for i in ap:
    if ap[i]<i:
        co+=ap[i]
    else:
        co+=(ap[i]-i)
print(co)

Submission status: Accepted

Solution code:
from collections import Counter
n = input()
xs = [int(c) for c in input().split()]
c = Counter(xs)
ans = 0
for x, cnt in c.items():
  ans += cnt if cnt < x else (cnt - x)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
freq = {}
for e in a:
    if e not in freq:
        freq[e] = 0
    freq[e] += 1
    if (freq[e] > e):
        ans += 1
        freq[e] -= 1

for e in freq:
    if e != freq[e]:
        ans += freq[e]

print(ans)

Submission status: Accepted

Solution code:
length = input()
nums = input().split(" ")

numdict = {}
for i, num in enumerate(nums):
	if num not in numdict:
		numdict[str(num)] = 1
	else:
		numdict[str(num)] += 1

ret = 0
for k,v in numdict.items():
	if int(k) > int(v):
		ret += int(v) 
	else:
		ret += int(v) - int(k)

print(ret)

Submission status: Accepted

Solution code:
input()
nums = input().split(" ")
# print(nums)
sett = set(nums)
dicto = {}
for a in range(len(sett)):
    dicto[str(sett.pop())] = 0
for a in nums:
    dicto[a] += 1
# print(dicto)
ans = 0
for k,v in dicto.items():
    k = int(k)
    if v>k:
        ans += v-k
    elif v<k:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby
from operator import itemgetter

line = input()
line = input().split(" ")

a = []
for x in line:
        a.append(int(x))

a.sort()

ret = 0
for k,g in groupby(a):
        g = list(g)
        if len(g)>k:
                ret += len(g)-k
        elif len(g)<k:
                ret += len(g)

print(ret)

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
a_lst=[int(_) for _ in input().split()]
counter=Counter(a_lst)
count=0
for k, v in counter.items():
    if v>=k:
        count+=v-k
    else:
        count+=v
print(count)

Submission status: Accepted

Solution code:
N = int(raw_input())
a = [int(x) for x in raw_input().split(" ")]

lookup = {}
for val in a:
    lookup[val] = 1 + (lookup[val] if lookup.has_key(val) else 0)

remove_num = 0
for val, count in lookup.items():
    remove_num += count if count < val else (count - val)

print remove_num

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

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

cnt = {}

for a in As:
    cnt.setdefault(a, 0)
    cnt[a] += 1

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

print(ans)

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    r = 0
    d = collections.Counter(a)
    for i,c in d.items():
        if i < c:
            r += c-i
        else:
            r += c%i

    return r



print(main())

Submission status: Accepted

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

from collections import Counter

cnt = Counter(A)

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

print(res)