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: Runtime Error

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
data = sorted(data) + [0]

if N == 1 and data[0] == 1:
    print(0)

elif N == 1 and data[0] != 1:
    print(1)

else:
    ans = 0
    num = data[0]
    cnt = 0
    for i in range(N+1):
        if data[i] == num:
            cnt += 1
        else:
            ans += min(abs(cnt-num),cnt)
            cnt = 1
            num = data[i]
print(ans)

Submission status: Runtime Error

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

for num in nums:
  if num in dict.keys():
    dict[num] += 1
  else:
    dict[num] = 1
ans = 0
for key, value in dict.items():
  if int(key) == value
    continue
  elif int(key) > value:
    ans += value
  else:
    ans += value - int(key)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
dp = [0]*max(a)
for i in set(a):
	cnt = a.count(i)
	if i < cnt: dp[i-1] = cnt - i
	elif i > cnt: dp[i-1] = cnt
print(sum(dp))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
dp = [0]*n
for i in set(a):
	cnt = a.count(i)
	if i < cnt: dp[i] = cnt - i
	elif i > cnt: dp[i] = cnt
print(sum(dp))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
dp = [0]*n
for i in set(a):
	cnt = a.count(i)
	if i < cnt: dp += cnt - i
	elif i > cnt: dp += cnt
print(sum(dp))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
dp = [0]*n
for i in set(a):
	cnt = a.count(i)
	if i < cnt: dp = cnt - i
	elif i > cnt: dp = cnt
print(sum(dp))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(N):
    if a[i] > 10**5:
        ans += 1
        del a[i]
        
import sys
if len(a) == 0:
    print(ans)
    sys.exit()

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

for i in a:
    counts[i] += 1
    
for i in range(len(counts)):
    if counts[i] == 0:continue
    if counts[i] < i:
        ans += counts[i]
    elif counts[i] > i:
        ans += counts[i]-i
        
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(N):
    if a[i] > 10**5:
        ans += 1
        del a[i]
        
import sys
if len(a) == 0:
    print(ans)
    sys.exit()

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

for i in a:
    counts[a] += 1
    
for i in range(len(counts)):
    if counts[i] == 0:continue
    if counts[i] < i:
        ans += counts[i]
    elif counts[i] > i:
        ans += counts[i]-i
        
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(N):
    if a[i] > 10**5+1:
        del a[i]
        ans += 1
        
counts = [0] * (10 ** 5 + 1)

for i in range(len(a)):
    counts[a[i]] += 1
    
for i in range(1,len(counts)):
    if counts[i] == 0:continue
    if counts[i] < i:
        ans += counts[i]
    elif counts[i] > i:
        ans += counts[i]-i
        
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())
dic = {}
for i in range(N):
  if dic.get(A[i]) is None: 
    dic[A[i]] = 1
  else:
    dic[A[i]] += 1

ans = 0
for k in dic:
  if dic[k] >= k:
    ans += abs(dic[k] - k)
  else:
    ans += dic[k]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
dic = {}
for i in range(N):
  num = int(input())
  if dic.get(num) is None: 
    dic[n] = 1
  else:
    dic[n] += 1

ans = 0
for k in dic:
  if dic[k] >= k:
    ans += abs(dic[k] - k)
  else:
    ans += dic[k]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in set:
    c = list.count(i)
    if c >i:
        cnt += c-i
    elif c <i:
        cnt += c
print(N - len(list)+cnt)

Submission status: Runtime Error

Solution code:
N = int(input())

cnt = 0
strdit = {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
for i in input().split():
    strdit[int(i)] += 1

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

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

max = max(a_n)
a_n_num = [0]*(max+1)
for i in range(len(a_n)):
    a_n_num[a_n[i]] += 1

counter = 0
for i in range(len(a_n_num)):
    if a_n_num[i] > i:
        counter += a_n_num[i] - i
    elif a_n_num[i] < i:
        counter += a_n_num[i]

print(counter)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
N=ni()
A=na()
A.sort()
n=0
ans=0
for i in range(N-1):
    n+=1
    if(A[i]==A[i+1]):
        continue
    else:
        if(n==A[i]):
            n=0
            continue
        elif(n>A[i]):
            ans=n-A[i]
        else:
            ans=n
        n=0

if(A[-1]!=A[-2]):
    ans+=1


print(ans)

Submission status: Runtime Error

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

count = Counter(a)
ans = 0
for i in count.keys():
    if count[i] < i:
        ans += count[i]
    else:
        ans += count[i] - i

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=input()
dc=dict()
for j in input().split():
    i=int(j)
    if i in dc:
        dc[i]+=1
    else:
        dc[i]=1
ans=0
for i in dc:
    if dc[i]>i:
        ans+=dc[i]-i,0
    elif dc[i]<i:
        ans+=dc[i]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

const int MAX_N = 100010;
int n;
int a[MAX_N];
vector<int> aa;
int cnt[MAX_N];

void input(){
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) aa.push_back(a[i]);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int ccnt = 0;
    for(int i=0;i<n;++i){
        if(aa[i] > 100000){
            aa.erase(aa.begin()+i);
            ++ccnt;
        }
    } // 100000を超える数は良い数列の邪魔なので削除
    int sz = aa.size();
    for(int i=0;i<sz;++i) cnt[aa[i]]++;
    for(int i=0;i<MAX_N;++i){
        if (i != cnt[i]){
            if(i < cnt[i]) ccnt += (cnt[i] - i);
            else ccnt += cnt[i];
        }
    }
    cout << ccnt << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
from collections import counter as C
print(9)

Submission status: Runtime Error

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
N,K = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
s = set(A)
for a in A:
    bucket[a]+=1
bucket = [n for n in bucket if n != 0]
rc = len(s) - K
ans = 0
for r in range(rc):
    tminid = bucket.index(tmin)
    ans += bucklet[tminid]
    bucket[tminid]=200006
print(ans if ans >=0 else 0)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
cnt = 0
ind = 1
while A != []:
  A = list(map(lambda x: x - 1, A))
  if(0 in A):
    zero = A.count(0)
    if(zero > ind):
      cnt += abs(zero - ind)
    elif(zero < ind):
      cnt += zero
    A = filter(lambda n: n != 0, A)
  ind += 1
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

summary = {}
for x in a:
    if x not in summary.keys():
        summary[x] = 1
    else:
        summary[x] += 1

res = 0
for k, v in summary.items():
    if k > v:
        res += v
    else:
        res += min(v - k, v)

print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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():
    del = max(val-key,val)
    if key == val:
        del = 0
    ans += del

print(ans)

Submission status: Runtime Error

Solution code:
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n = gif

a = gi

b = Hash.new
a.each do |aa|
b[aa] ||= 0
b[aa] += 1
end
ans = 0
b.each do |key,value|
  if value >= key
  ans += value - key
else
  ans += value
end
end

puts ans

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#ABC083
import math
X, Y=map(int,input().split())
print(int(math.log(Y/X, 2)//1+1))

Submission status: Runtime Error

Solution code:
#ABC083
import math
X, Y=map(int,input().split())
print(int(math.log(Y//X, 2)+1))

Submission status: Runtime Error

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)
    ans += ai_count - ai if ai_count >= ai else ai_count

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 01:03:03 2018

@author: Yuki
"""
import numpy as np

N = int(input())
A = sorted([int(i) for i in input().split()])
#N = 8
#A = sorted([2, 7, 1, 8, 2, 8, 1, 8])
A_uni = np.array(sorted(list(set(A))))
A = np.array(A)


tmp = 0
res_cnt = 0
i = 0
for i in range(len(A_uni)):
    tmp_number = A_uni[i]
    if len(A) <= tmp_number+1:
        res_cnt += len(A)
        break
    else:
        if A[tmp_number-1] != tmp_number:
            del_cnt = 1
            while True:
                if A[del_cnt] == tmp_number:
                    del_cnt += 1
                else:
                    res_cnt += del_cnt
                    A = A[del_cnt:]

                    break
        else:
            if A[tmp_number] != tmp_number:
                A = A[tmp_number:]
            else:
                A = A[tmp_number:]
                del_cnt = 1
                while True:
                    if A[del_cnt] != tmp_number:
                        A = A[del_cnt:]
                        res_cnt += del_cnt
                        break
                    else:
                        del_cnt += 1
                    
print(res_cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
h = list(map(int, input().split()))
a = list(set(h))
s = 0
l = len(a)
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)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a.sort()
for i in range(N):
    if

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 22 10:08:31 2018

@author: Yuya
"""

N=int(input())

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

a.sort()
count_sum=0
count = 1

for i in range(N-1):
    flag=-1
    if a[i+1]!=a[i]:
        if count>a[i]:
            count_sum += count-a[i]
        elif count<a[i]:
            count_sum += count
        count=1
        flag=1
    else:
        count+=1

if flag==-1:
    if count>a[N-1]:
        count_sum += count-a[N-1]
    elif count<a[N-1]:
        count_sum += count

print(count_sum)

Submission status: Runtime Error

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 + 1 - k
        k = count 
        
        if count < a[i]:
            res += count
        else:
            res += count - a[i]
        
for i in range(a[-1]):
    if a[-1] != a[-i]:
        res += 1
        break
        
        
print(res)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

d = Counter(A).most_common()
d = d[::-1]

reCounter = 0

for i in range(len(d)):
    if d[i][0] < d[i][1]:
        reCounter += d[i][1] - d[i][0]
    if d[i][0] > d[i][1]:
        reCounter += d[i][1]
        
print(reCounter)

Submission status: Runtime Error

Solution code:
input()
l = list(map(int,input().split()))
m = set(l)
a = 0
for i in(m):
    while l.count(i) != i:
        l.remove(i)
        a += 1

print(a)

Submission status: Runtime Error

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

sort_dict = collections.Counter(a_list)

remove_counter = 0

for key, value in sort_dict.items():
    if value < key:
        remove_counter += value
    elif value == key:
        pass
    else:
        remove_counter += (value - key)
        
print(remove_counter)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [0 for i in range (10000000)]
for i in range (N):
    b[a[i]] += 1
tot = 0
for i in range (1, 10000000):
    if  0 < b[i] < i:
        tot += b[i]
    elif b[i] > i:
        tot += b[i]-i
print(tot)

Submission status: Runtime Error

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

anset = list(set(an))

andict = {}

for i in range(len(an)):
    if an[i] in andict:
        andict[an[i]] = andict[an[i]] + 1
    else:
        andict.update({an[i]:1})

counter = 0

for i ,j in andict.keys(), andict.values():
    if i == j :
        None
    elif i > j:
        counter = counter + j
    elif i < j:
        counter = counter + j - i
    
        
print(counter)

Submission status: Runtime Error

Solution code:
n=int(input())
a=input().split()
dict={}
for i in a:
  if i not in dict:
    dict[i]=1
  else:
    dict[i]+=1

ans=0
for i in dict.keys():
  count=dict[i]
  if count>i:
    ans+=count-i
  elif count<i:
    ans+=count

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=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: Runtime Error

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * N
for i in range(N):
    b[a[i]] += 1

ans = 0

for i in range(N):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy
n = int(input())
x = [int(i) for i in input().split()]
y = copy.deepcopy(x)
z = []
for j in x:
	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)
	z.append(j)
print(len(x)-len(y))

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(raw_input())
c = Counter(map(int, raw_input().split()))
s = 0
for k,v in c:
    if v < k:
        s += v
    else:
        s += v - k
print s

Submission status: Runtime Error

Solution code:
# 4
# 3 3 3 3
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 = a.get(i, 0)
  if v >= i:
    result += v - i
  else:
    result += v
print(result)

Submission status: Runtime Error

Solution code:
from collections import Counter
a = int(input())
l = []
i = 1
for i in range(a):
    b = [int(i) for i in input(i).split(" ")]
    l.append(b)
c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Submission status: Runtime Error

Solution code:
from collections import Counter
a = int(input())
l = []
for i in range(0,a):
    b = int(input())
    l.append(b)
c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Submission status: Runtime Error

Solution code:
from collections import Counter
a = int(input())
l = []
for i in range(0,a):
    b = int(input())
    l.append(b)
c=Counter(l)
d = dict(c)
#print(d)
kv = []
for k,v in d.items():
    if k>v:
        t = v
        kv.append(t)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Submission status: Runtime Error

Solution code:
from collections import Counter
a = int(input())
l = []
for i in range(0,a):
    b = int(input())
    l.append(b)
c=Counter(l)
d = dict(c)
print(d)
kv = []
for k,v in d.items():
    if k>v:
        t = v
        kv.append(t)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Submission status: Runtime Error

Solution code:
from collections import Counter
a = int(input())
l = []
for i in range(0,a):
    b = int(input())
    l.append(b)
c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        t = v
        kv.append(t)
    elif k<v:
        t = v-k
        kv.append(t)
    elif k==v:
       t= 0
       kv.append(t)        
s = sum(kv)
print(s)

Submission status: Runtime Error

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

answer=0
count_sum=0

counter = Counter(a)
for num, cnt in counter.most_common():
#  print (num, cnt)
  count_sum+=cnt
  if cnt>num:
    answer += cnt-i
  elif cnt<num:
    answer += cnt
answer+=N-count_sum
print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())

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

place = [0 for _ in range(100000)]
counter = 0
max = 0

for i in series:
    place[i] += 1
    if i > max:
        max = i
    
for j in range(len(place)):
    if place[j] > j:
        counter += place[j] - j
    elif j > place[j]:
        counter += place[j]
        
print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())

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

lis.sort()

Ans = 0

p = 0

while(True):
	
	if p >= N:
		break
	
	if lis[p] > lis.count(lis[p]):
		Ans += lis.count(lis[p])
		p += lis.count(lis[p])
	
	if lis[p] == lis.count(lis[p]):
		p += lis.count(lis[p])
	
	if lis[p] < lis.count(lis[p]):
		Ans += lis.count(lis[p]) - lis[p]
		p += lis.count(lis[p])
		
print(Ans)

Submission status: Runtime Error

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

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

a.sort()
numbers=[int(i) for i in set(a)]
numbers.sort()

# print("a", a)
# print("numbers", numbers)

def main():
    label=0 # numbersの添字
    i=0 # aの添字
    err=0 # 削除する要素の数
    while(True):
        # 範囲を超えるパターン
        if(len(numbers) <= label or len(a) <= i):
            # print("Exit")
            return err
        # 最初が一致
        if(a[i]==numbers[label]):
            # 要素数分を確保
            ar=[ numbers[label] ] * numbers[label]
            # ピッタリ一致
            if(a[ i:i+numbers[label] ] == ar):
                # print("[ fit ] i="+str(i))
                # print("a["+str(i)+"]="+str(a[i]))
                i += numbers[label]
                label += 1
            # 最初が一致かつ不完全一致
            else:
                # print("[unfit] i="+str(i))
                for j in range(0, i):
                    try:
                        # 値が不一致(要素)
                        # print("a[i+j]="+str(a[i+j]))
                        # print("numbers[label]="+str(numbers[label]))
                        if(a[i+j]!=numbers[label]):
                            # print("Unmatched: j=", j)
                            i+=j
                            err+=j
                            break
                    except IndexError:
                        err+=j
                        # print("i, j=", i, j)
                        return err
        # 最初が不一致(右に1つずらす)
        else:
            err+=1
            i+=1

if(N==1):
    if(a[0]==1):
        print(0)
    else:
        print(1)
else:
    print(main())

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    l = list(map(int,input().split(" ")))
    dic = {}
    count = 0
    for i in l:
        try:
            dic[i] += 1
        except Exception:
            dic[i] = 1

    for j in range(1, len(dic)):
        count += (dic[j] - j) if dic[j] > j else dic[j]
    print(count)


if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
N = input()
list = [int(a) for a in input().split()]
count = 0
for i in range(len(list)):
    if list[i] != list.count(list[i]):
        list.remove(list[i])
        count += 1
    if i == len(list)-1:
        break
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())						# 5
b = list( map(int, input().split()) )
a = []

#print("N", N)
#print("b", b)

big = 0
#でかいのを除外する
for i in b:
	if i <= 10000:
		a.append(i)
	else:
		big += 1

if len(a) == 0:
	print(big)
	exit(0)

l=[0]*( max(a) +1)


for i in b:
	l[i] += 1

#print("l", l)

ans=big

for i in range( len(l) ):
	if l[i] == 0: continue
	if l[i] == i: continue
	
	x=1000000000 + 1
	y=1000000000 + 1
	if l[i] > i: x = l[i] - i
	if l[i] < i: y = l[i]
	
	ans += min(x, y)
	

print(ans)

Submission status: Runtime Error

Solution code:
N = input()
list = [a for a in input().split()]
count = 0
A = len(list)
for i in range(A):
#    print(list[i])
 #   print(list.count(list[i]))
    if list[i] != list.count(list[i]):
        list.remove(list[i])
        count += 1
    if i == len(list)-1:
        break
 #   print(list)
 #   print(count)
print(count)

Submission status: Runtime Error

Solution code:
N = input()
list = [a for a in input().split()]
count = 0
for i in range(len(list)):
#    print(list[i])
 #   print(list.count(list[i]))
    if list[i] != list.count(list[i]):
        list.remove(list[i])
        count += 1
    if i == len(list)-1:
        break
 #   print(list)
 #   print(count)
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int, input().split()))
li = [0] * (max(l) + 1)
count = 0
for i in range(len(l)):
    h = l[i]
    li[h] += 1
for j in range(len(li)):
    if li[j] == j:
        continue
    elif li[j] < j:
        count += li[j]
    elif li[j] > j:
        count += (li[j] - j)
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int, input().split()))
li = [0] * (max(l) + 1)
count = 0
for i in range(len(l)):
    h = l[i]
    li[h] += 1
for j in range(len(li)):
    if li[j] == j
      continue
    elif li[j] < j:
        count += li[j]
    elif li[j] > j:
        count += (li[j] - j)
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

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

total = 0

for i in range(n):
    if a[i] > 10**5:
        total = n - i
        a = a[0:i]
        break

a = np.array(a)

u, c = np.unique(a, return_counts=True)

# print(u, c)

end = (10**5) + 1
i = 1
for (i, cnt) in zip(u, c):
    num = 0
    if cnt == i:
        end -= cnt
    elif cnt == 0:
        pass
    elif cnt > i:
        total += (cnt - i)
    else:
        num = i - cnt
        if num < cnt:
            total += num
        else:   
            total += cnt

print(total)

Submission status: Runtime Error

Solution code:
import numpy as np

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

a_l = np.sort(a_l)

r = 0
while 0 != len(a_l):
    c = a_l.count(a_l[0])
    if c > a_l[0]:
        r += c - a_l[0]
    elif c != a_l[0]:
        r += c
    a_l = a_l[c:]

print(r)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int, input().split()))
li = [0] * (max(l) + 2)
count = 0
for i in range(len(l)):
    j = l[i]
    li[j] += 1
for j in range(len(li)):
    if li[j] < j:
        count += li[j]
    elif li[j] > j:
        count += (li[j] - j)
    elif li[j] == j:
        count += 0
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int, input().split()))
li = [0] * (max(l) + 2)
count = 0
for i in range(len(l)):
    j = l[i]
    li[j] += 1
for j in range(len(li)):
    if li[j] < j:
        count += li[j]
    elif li[j] > j:
        count += (li[j] - j)
    else:
        continue
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int, input().split()))
li = [0] * (max(l) + 1)
count = 0
for i in range(len(l)):
    j = l[i]
    li[j] += 1
for j in range(len(li)):
    if li[j] < j:
        count += li[j]
    elif li[j] > j:
        count += (li[j] - j)
    else:
        continue
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
l = list(map(int, input().split()))
li = [0] * (max(l) + 1)
count = 0
for i in range(len(l)):
    j = l[i]
    li[j] += 1
for j in range(len(li)):
    if li[j] == 0:
        continue
    elif li[j] < j:
        count += li[j]
    elif li[j] > j:
        count += (li[j] - j)
    else:
        continue
print(count)

Submission status: Runtime Error

Solution code:
# coding:utf-8
N = int(input())
a = input().split()
a_ = list(map(int, a))

#back_a = list(map(lambda x:x*0, list(range(N))))

back_i = 0
back_i2 = 0
for i in range(N):
    a_count = a[i-back_i]
    if a_count > int(a[i-back_i]):
        del a[i-back_i]
        back_i += 1
        #back_i2 += 
    if a_count < int(a[i-back_i]):
        del a[i-back_i]
        back_i += 1

print(back_i)