Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

Constraints

1 \leq N \leq 10^5

a_i is an integer.

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

4
3 3 3 3

Sample Output 1

1

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

Sample Input 2

5
2 4 1 4 2

Sample Output 2

2

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

Sample Input 3

6
1 2 2 3 3 3

Sample Output 3

0

Sample Input 4

1
1000000000

Sample Output 4

1

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

Sample Input 5

8
2 7 1 8 2 8 1 8

Sample Output 5

5



Sample input:
4
3 3 3 3


Sample output:
1

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
a.sort()
A = 0
c = 0
while True:
    try:
        #print(a)
        A = a[0]
        if len(a)>1:
            for i in range(1, len(a)):
                if a[i] != A:
                    # print(i + 1)
                    # c += i
                    del a[:i]
                    if i >= A:
                        c += i - A
                    else:
                        c += i
                    # print(a[i], c)
                    break
                elif i == len(a) - 1:
                    if i + 1 >= A:
                        c += i + 1 - A
                    else:
                        c += i + 1
                    print(c)
                    exit()
        else:
            print(c + 1)
            exit()
    except IndexError:
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
A = 0
c = 0
if len(a) == 1:
    print(1)
    exit()
while True:
    try:
        #print(a)
        A = a[0]
        for i in range(1, len(a)):
            if a[i] != A:
                # print(i + 1)
                # c += i
                del a[:i]
                if i >= A:
                    c += i - A
                else:
                    c += i
                # print(a[i], c)
                break
            elif i == len(a) - 1:
                if i + 1 >= A:
                    c += i + 1 - A
                else:
                    c += i + 1
                print(c)
                exit()
    except IndexError:
        break

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n==6 and ' '.join([str(x) for x in l])=='1 2 2 3 3 3':
  exit()
sl=list(set(l))
c=0
for i in range(len(sl)):
  a=sl[i]
  b=l.count(a)
  if a>b:
    c+=b
  else:
    c+=b-a
print(c)

Submission status: Wrong Answer

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

ans = 0
d = {}

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = 0
for i in range(1, max(a)+1):
  if i in a:
    c += abs(i - a.count(i))
print(c)

Submission status: Wrong Answer

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

if max(a)>N:
  print N
else:
  T = [0]*(N+1)
  for x in a:
    T[x] += 1
  ans = 0
  for i in range(N+1):
    if T[i]>0:
      if T[i]>=i:
        ans += T[i]-i
      else:
        ans += T[i]
  print ans

Submission status: Wrong Answer

Solution code:
#ABC082C
N=int(input())
A=list(map(int,input().split()))
ans=0
for s in set(A):
	c=A.count(s)
	ans+=min(c,abs(s-c))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
c = 0
d = 0
for i in range(n):
  if a[i] != c:
    if a.count(c) >= a[i]:
      d += a.count(a[i]) - a[i]
    else:
      d += a.count(a[i])
    c = a[i]
print(d)

Submission status: Wrong Answer

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

# c(i)をiのaにおける個数とする
res = 0

for i in set(a):
    ci = a.count(i)
    # c(i) > iの時は c(i) = i になるまで取り除くしかない
    if ci > i:
        res += ci - i
    # c(i) < iの時は，奇数偶数で場合分け
    elif ci < i:
        if ci == i / 2:
            res += i // 2
        elif ci > i / 2:
            res += i - ci
        else:
            res += ci

print(res)

Submission status: Wrong Answer

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

# c(i)をiのaにおける個数とする
res = 0

for i in set(a):
    # c(i) > iの時は c(i) = i になるまで取り除くしかない
    if a.count(i) > i:
        res += a.count(i) - i
    # c(i) < iの時は，奇数偶数で場合分け
    elif a.count(i) < i:
        if a.count(i) == i / 2:
            res += i // 2
        elif a.count(i) > i / 2:
            res += i - a.count(i)
        else:
            res += a.count(i)

print(res)

Submission status: Wrong Answer

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

count = [0] * (10 ** 5 + 1)

for i in a:
    if i <= 10 ** 5:
        count[i] += 1
ans = 0
for i,j in enumerate(count):
    if (j - i) >= 0:
        ans += j - i
    else:
        ans += j
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter

n = input()
a = np.array([int(i) for i in input().split()])

x = Counter(a)
out = 0
for i in x:
    if(i < i):
        out += x[i]
    else:
        out += x[i] - i

print(out)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

import collections as coll
cnt = coll.Counter(L)
ans = 0
for x in cnt.items():
    if x[0] > x[1]:
        ans += x[1]
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    ai = a.count(i+1)
    if ai > i+1:
        ans += ai - i-1
    if ai < i+1:
        ans += ai

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ans = 0
for a, cnt in Counter(A).items():
  if not (a == cnt):
    if abs(a - cnt) < cnt:
      ans += abs(a - cnt)
    else:
      ans += cnt
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ans = 0
for a, cnt in Counter(A).items():
  if not a == cnt:
    if abs(a - cnt) < cnt:
      ans += abs(a - cnt)
    else:
      ans += cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_set = list(set(A))
cnt = 0
for _as in A_set:
  a_count = A.count(_as)
  if not _as == a_count:
    if abs(a_count - _as) < a_count:
      cnt += abs(a_count - _as)
    else:
      cnt += a_count
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
B = set(A)
ans = 0
for i in B:
    index = A.count(i)
    if(index > i):
        ans+=index - i
    elif(index < i):
        ans+=index
    del A[:index]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
B = set(A)
ans = 0
for i in B:
    index = A.count(i)
    if(index > i):
        ans+=index - i
    elif(index < i):
        ans+=index
    del A[:i]
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
C = Counter(A).most_common()

Ans = 0
for (k,v) in C:
    if k==v:
        continue
    else:
        Ans += min(v,abs(v-k))

print(Ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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

dic = {}
for ak in a:
    if not(ak in dic):
        dic[ak] = 1
    else:
        dic[ak] += 1
ans = 0
for k in dic.keys():
    if(dic[k] - k > 0):
        ans+=dic[k] - k
    elif(dic[k] - k < 0):
        ans+=min(k-dic[k],dic[k])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
dic = {}
ans_list = [10000000000]
for a in a_list:
    dic[a] = 0
for a in a_list:
    dic[a] += 1
for a in a_list:
    ans = dic[a] - a 
    if ans >= 0:
        ans_list.append(ans)
if min(ans_list) == 10000000000:
    print(n)
else:
    print(min(ans_list))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=set(a)
ans=0
for i in b:
    if i-a.count(i)>=0:
        ans+=i-a.count(i)
    else:
        ans+=i
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)
ans = 0

for key,val in c.items():
    d = max(val-key,val)
    if key == val:
        d = 0
    ans += d

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)
ans = 0

for key,val in c.items():
    ans += min(val,abs(key-val))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n=int(input())
l=list(map(int,input().split()))
li=collections.Counter(l)
print(li)
a=0
for k,v in li.items():
    if k>v:
        a+=v
    else:
        a+=v-k
print(a)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = [int(i) for i in input().split()]
hint = collections.Counter(a)
b = hint.most_common()
ans = 0
for val, num in b:
    if val != num:
        ans += min(num,abs(num-val))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = [int(i) for i in input().split()]
hint = collections.Counter(a)
b = hint.most_common()
ans = 0
for val, num in b:
    if val != num:
        ans += num
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a =list(map(int,input().split()))
col = collections.Counter(a)
a = set(a)
cnt = 0
for letter in a:
    if letter != col[letter]:
        cnt += col[letter]
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a =list(map(int,input().split()))
col = collections.Counter(a)
a = set(a)
cnt = 0
for letter in a:
    cnt += min(col[letter] - letter,col[letter])
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a =list(map(int,input().split()))
col = collections.Counter(a)
a = set(a)
cnt = 0
for letter in a:
    cnt += min(abs(letter - col[letter]),col[letter])
print(cnt)

Submission status: Wrong Answer

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

a = sorted(a)
ans = n
i = 0
while i < n:
    temp = a[i]
    count = 1
    while 1:
        if a[i] != temp:
            break
        i += 1
        if i >= n:
            break
        count += 1
    if count >= temp:
        ans -= temp

print(ans)

Submission status: Wrong Answer

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

a = sorted(a)
ans = n
i = 0
while i < n:
    temp = a[i]
    count = 1
    while i < n:
        if a[i] != temp:
            break
        count += 1
        i += 1
    if count >= temp:
        ans -= temp

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]

cnt = 0
b = set(a)

for i in b:
    if i > 10**5:
        cnt += i
        continue
    c = a.count(i)
    if c > i:
        cnt += c - i
    elif c == i:
        continue
    else:
        cnt += c

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]

cnt = 0
b = set(a)

for i in b:
    if i > 10**5:
        a.remove(i)
        cnt += i
        continue
    c = a.count(i)
    if c > i:
        cnt += c - i
    elif c == i:
        continue
    else:
        cnt += c

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]

cnt = 0
for i in a:
    if i > 10**5:
        a.remove(i)
        cnt += i
    else:
        break

b = set(a)

for i in b:
    c = a.count(i)
    if c > i:
        cnt += c - i
    elif c == i:
        continue
    else:
        cnt += c

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]

for i in a:
    if i > 10**5:
        a.remove(i)
    else:
        break

cnt = 0

b = set(a)

for i in b:
    c = a.count(i)
    if c > i:
        cnt += c - i
    elif c == i:
        continue
    else:
        cnt += c

print(cnt)

Submission status: Wrong Answer

Solution code:
#ABC082C
N=int(input())
a_sorted=sorted(list(map(int,input().split())))
#必要な変数の作成
Allowable_original=0
Allowable_count=0
Delete_count=0
#aが要素1個のみの場合
if N==1:
    if a_sorted==1:
        print(0)
    else:
        print(1)
    exit()
#順番にチェック
for i in range(N):
    #開始処理
    if i==0:
        #許容個数カウントとその元値を作成
        Allowable_original=a_sorted[0]
        Allowable_count=Allowable_original-1
        continue

    #前の数字と同じか否か
    # 同じなら、
    if a_sorted[i]==a_sorted[i-1]:
        #許容個数カウントを一つ減らす
        Allowable_count-=1
    # 違うなら、または末尾なら、
    if a_sorted[i]!=a_sorted[i-1]:
        # 許容個数カウントの現在値が正か0か負かチェック
        # 正なら、
        if Allowable_count>0:
            #カウントしてきた許容個数（許容個数カウントの元値-現在値）を削除対象カウントに追加
            Delete_count+=Allowable_original-Allowable_count
        #0以下なら、
        else:
            # -1をかけた値を削除対象カウントに追加
            Delete_count-=Allowable_count
        # 許容個数カウントとその元値を新規作成
        Allowable_original = a_sorted[i]
        Allowable_count = Allowable_original - 1
    #末尾なら、
    if i==N-1:
        # 許容個数カウントの現在値が正か0か負かチェック
        # 正なら、
        if Allowable_count>0:
            #カウントしてきた許容個数（許容個数カウントの元値-現在値）を削除対象カウントに追加
            Delete_count+=Allowable_original-Allowable_count
        #0以下なら、
        else:
            # -1をかけた値を削除対象カウントに追加
            Delete_count-=Allowable_count
#結果出力
print(Delete_count)

Submission status: Wrong Answer

Solution code:
#ABC082C
N=int(input())
a_sorted=sorted(list(map(int,input().split())))
#必要な変数の作成
Allowable_original=0
Allowable_count=0
Delete_count=0
#aが要素1個のみの場合
if N==1:
    if a_sorted==1:
        print(0)
    else:
        print(1)
    exit()
#順番にチェック
for i in range(N):
    #開始処理
    if i==0:
        #許容個数カウントとその元値を作成
        Allowable_original=a_sorted[0]
        Allowable_count=Allowable_original-1
        continue

    #前の数字と同じか否か
    # 同じなら、
    if a_sorted[i]==a_sorted[i-1]:
        #許容個数カウントを一つ減らす
        Allowable_count-=1
    # 違うなら、または末尾なら、
    if a_sorted[i]!=a_sorted[i-1] or i==N-1:
        # 許容個数カウントの現在値が正か0か負かチェック
        # 正なら、
        if Allowable_count>0:
            #カウントしてきた許容個数（許容個数カウントの元値-現在値）を削除対象カウントに追加
            Delete_count+=Allowable_original-Allowable_count
        #0以下なら、
        else:
            # -1をかけた値を削除対象カウントに追加
            Delete_count-=Allowable_count
        # 許容個数カウントとその元値を新規作成
        Allowable_original = a_sorted[i]
        Allowable_count = Allowable_original - 1
#結果出力
print(Delete_count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
T = list(set(A))
answer = 0
for i in range(len(T)) :
    answer += min(A.count(T[i]),abs(A.count(T[i])-T[i]))
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
i = 0
k = 1
ans = 0
if (len(L) == 1):
  if (L[0] == 1):
    ans = 0
  else: 
    ans = 1   
else: 
  while (i < len(L)-1):
    if (L[i] == L[i+1]):
      i += 1
      k += 1
      if (i == len(L)):
        if (k >= L[i]):
          ans += k-L[i]
        else:
          ans += k
          break
    else:
      if (L[i] <= k):
        ans += k-L[i]
        k = 1
        i += 1
      else:
        ans += k
        k = 1
        i += 1
print(ans)

Submission status: Wrong Answer

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

for ai in set_a:
  ai_count = a.count(ai)
  if ai_count > ai:
  	ans += ai_count - ai  
  else:
    ans += ai_count

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from scipy.misc import comb
N=int(input())
a=map(int, input().split())
counter=Counter(a)
ckeys=list(counter.keys())
ans=0
for i in ckeys:
    if i>counter[i]:
        ans+=min(i-counter[i], counter[i])
    elif i<counter[i]:
        ans+=counter[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from scipy.misc import comb
N=int(input())
a=map(int, input().split())
counter=Counter(a)
ckeys=list(counter.keys())
ans=0
for i in ckeys:
    if i!=counter[i]:
        ans+=min(abs(i-counter[i]), counter[i])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from scipy.misc import comb
N=int(input())
a=map(int, input().split())
counter=Counter(a)
ckeys=list(counter.keys())
ans=0
for i in ckeys:
    if i>counter[i]:
        ans+=min(i-counter[i], counter[i])
    elif i<counter[i]:
        ans+=counter[i]-i
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    h = list(map(int, input().split()))
    a = list(set(h))
    s = 0
    l = len(a)
    if n == 1 and h[0] == 1:
        print(0)
        return
    else:
        print(1)
        return
    while h.count(a[l-1]) != a[l-1]:
        h.remove(a[l-1])
        s += 1
        if h.count(a[l-1]) == 0:
            a.pop()
        l = len(a)
    print(s)

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))

npA = np.sort(A)

ans = 0
while len(npA) > 0 and N > npA[0]:
    i = np.min(npA)
    tmp = np.sum(npA == i)
    if tmp > i:
        ans += tmp - i
    elif tmp < i:
        ans += tmp
    npA = np.delete(npA, range(tmp))


print(ans + len(npA))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))

npA = np.sort(A)

ans = 0
if N < npA[0]:
    print(N)
    exit()

while len(npA) > 0 and N > npA[0]:
    i = np.min(npA)
    tmp = np.sum(npA == i)
    if tmp > i:
        ans += tmp - i
    elif tmp < i:
        ans += tmp
    npA = np.delete(npA, range(tmp))


print(ans + len(npA))

Submission status: Wrong Answer

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

arr = map(int,raw_input().split())

counter = collections.Counter(arr)

ans = 0 

for item in counter.items() :
	if item[0] == item[1]:
		next

	elif item[1] <= item[0]/2:
		ans += item[1]

	else :
		ans += abs(item[0]-item[1])

print ans

Submission status: Wrong Answer

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

cnt = int(input())
input_list = [int(i) for i in input().split()]

num_dict = {}
# 各数値ごとに数を集計
for num in input_list:
    # 辞書にその数値のキーが存在すれば+1追加
    if num in num_dict:
        num_dict[num] += 1
    # なければ新たにキー作成
    else:
        num_dict[num] = 1

ans = 0
# 数値と個数を揃えるのと、その数値をなくすのを、どちらが早いか見る
for key, value in num_dict.items():
    # valueのが大きければ無条件に揃える方が早い
    if key < value:
        ans += value - key
    else:
        # 揃える方が早い
        if value >= key - value:
            ans += key - value
        # なくす方が早い
        else:
            ans += value
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
res = 0
a.sort()
k = 0
for i in range(N-1):
    if a[i] != a[i+1]:
        
        count = i - k + 1
        k = i
        
        if k < a[i]:
            res += count
        else:
            res += count - a[i]
        
        
print(res+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N):
    X = a.count(i+1)
    if a[i] > N:
        res += N - i
        break
        
    elif X < i+1:
        res += X
        i = i  + X
        
    else:
        res += X - (i+1)
        i = i  + X
        
print(res)

Submission status: Wrong Answer

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

for i in range(N):
    if a[i] > N:
        res += 1
        
    elif a.count(i+1) < i+1:
        res += a.count(i+1)
        
    else:
        res += a.count(i+1) - (i+1)
        
print(res)

Submission status: Wrong Answer

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

for i in range(N):
    if a.count(i+1) < i+1:
        res += a.count(i+1)
    else:
        res += a.count(i+1) - (i+1)
        
print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
count=0
now=0
for i in range (N):
    if A[i]==now:
        pass
    elif A.count(A[i])>A[i]:
        count+=A.count(A[i])-A[i]
    else: 
        count+=A.count(A[i])
    now=A[i]
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
now = l[0]
count = 1
if len(l) == 1:
  if not now == 1:
    print(1)
else:
  for i in range(1, n):
    if l[i] == now:
      count += 1
    else:
      if count < now:
        ans += count
      elif count > now:
        ans += count-now
      
      now = l[i]
      count = 1
    
    if i == n-1:
      if count < now:
        ans += count
      elif count > now:
        ans += count-now

  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
cnt = Counter(map(int, input().split()))
print(cnt)
print(sum(v - k if v >= k else v for k, v in cnt.items()))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans =0
for i in set(a):
    if i>a.count(i):
        ans+=min(i-a.count(i), a.count(i))
    elif i<a.count(i):
        ans+=a.count(i)-i
print(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] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
ans = 0
for i in dic:
    if dic[i] < i:
        ans += dic[i]
    else:
        ans += i-dic[i]
print(ans)

Submission status: Wrong Answer

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

anset = list(set(an))

counter = 0

for i in range(len(anset)):
    while an.count(anset[i]) > anset[i]:
        couonter = counter + 1
        an.remove(anset[i])
    while 0 < an.count(anset[i]) < anset[i]:
        counter = counter + 1
        an.remove(anset[i])
        
print(counter)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * (N + 1)
for i in range(N):
    if a[i] <= N:
        b[a[i]] += 1
 
ans = 0
 
for i in range(N + 1):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
x = [int(i) for i in input().split()]
y = copy.deepcopy(x)
z = []
for j in x:
	z.append(j)
	if j not in z and x.count(j)<j:
		while y.count(j) != 0: y.remove(j)
	elif j not in z and x.count(j)>j:
		while y.count != j: y.remove(j)
print(len(x)-len(y))

Submission status: Wrong Answer

Solution code:
import collections

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

count = collections.Counter()

for a in A:
    count[a] += 1
    
ans = 0

for num, c in count.items():
    if num < c:
        ans += c - num
    elif num > c:
        ans += c
    else:
        continue

Submission status: Wrong Answer

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

for i in a:
    m[i] = m.get(i, 0) + 1

result = 0
for i in range(n + 1):
    v = m.get(i, 0)
    if v >= i:
        result += v - i
    else:
        result += v
print(result)

Submission status: Wrong Answer

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

for i in a:
  m[i] = m.get(i, 0) + 1

result = 0
for i in range(n):
  v = m.get(i, 0)
  if v >= i:
    result += v - i
  else:
    result += v
print(result)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
count_delete = 0
count_dict = collections.Counter(a)
print (count_dict)
for k, v in count_dict.items():
    if k != v:
        if k > v:
            count_delete += v
        else:
            count_delete += min(v-k, v)
print(count_delete)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def C_Good_Sequence():
    N=int(input())
    a=list(map(int, input().split()))
    b=set(a)
    b=list(b)
    count=0
    ans=0 
    c=[]
    
    for i in b:
        for j in range(N):
            if a[j]==i:
                count += 1
        c.append(count)
        count=0
    print(c)
    print(b)
    
    for i in range(len(b)):
        if c[i]<b[i]:
            ans += c[i]
        elif c[i] >b[i]:
            ans += c[i]-b[i]
    print(ans)
   
C_Good_Sequence()

Submission status: Wrong Answer

Solution code:
def C_Good_Sequence():
    N=int(input())
    a=list(map(int, input().split()))
    print(a)
    b=set(a)
    print(b)
    count=0
    ans=0
    
    for i in b:
        for j in range(N):
            if a[j]==i:
                count += 1
        print(i,count)
        if count<i:
            ans += count
        elif count >i:
            ans += count-i
        count=0
    print(ans)
    
C_Good_Sequence()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
dict = {}
for i in range(N):
    if(a[i] in dict):
        dict[a[i]] += 1
    else:
        dict[a[i]] = 1
l = list(dict.keys())
ans = 0
for i in range(len(l)):
    ans += min(dict[l[i]], abs(dict[l[i]] - l[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

count=Counter(a)
flow=0


for i in range(1,n+1):
    if (count[i]>i):
        flow+=count[i]-i
    elif (count[i]<i):
        flow+=count[i]

print(flow)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
count=Counter(a)
flow=0
for i in range(1,n+1):
    if (count[i]>i):
        flow+=1
    elif (count[i]<i):
        flow+=count[i]
print(flow)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    total = 0
    for i, a in enumerate(A):
        b = B.get(a, 0)
        if b == 0:
            B[a] = 1
        else:
            B[a] += 1

    for i in B:
        if B[i] == 0:
            continue
        total += min(abs(B[i]-i), B[i])
    print(total)
main()

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    a=list(map(int,input().split()))
    c=set(a)
    count=0
    for i in c:
        w=a.count(i)
        if w!=i:
            if i<w:
                count+=i
            else:
                count+=w
    return count
print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

C = dict(Counter(a))

ans = 0
for num, kosu in C.items():
    ans += min(kosu, abs(kosu-num))

print(ans)

Submission status: Wrong Answer

Solution code:
ignore = int(raw_input())
k = map(int, raw_input().split())
copyk = list(k)
times = 0
for i in range(ignore-1):
    if (copyk.count(k[i]) > k[i]):
        counter = (k.count(k[i])-k[i])
        while(counter > 0):
            copyk.remove(k[i])
            counter -= 1
            times += 1
    elif (copyk.count(k[i]) < k[i]):
        while(k[i] in copyk):
            copyk.remove(k[i])
            times += 1

if len(k) == 1:
    print 1
    exit()
elif len(k) == 0:
    print 0
    exit()
print times