stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

map<int,int> mp,flag;



int main()

{

    int n;

    cin>>n;

    int a[n+2],ans=0;

    for(int i=0;i<n;i++)

    {

        cin>>a[i];

        mp[a[i]]++;

    }

    for(int i=0;i<n;i++)

    {

        if(flag[a[i]]) continue;

        if(mp[a[i]]<a[i]) ans+=mp[a[i]];

        else ans+=(mp[a[i]]-a[i]);

        flag[a[i]]=1;

    }

    cout<<ans<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;



int a[100005],b[100005],c[100005];



int main(){

	int ans=0;

	int n;

	scanf("%d",&n);

	for(register int i=1;i<=n;i++){

		scanf("%d",&a[i]);

	}

	int m=0;

	sort(a+1,a+n+1);

	for(register int i=1;i<=n;i++){

		if(a[i]!=c[m]){

			c[++m]=a[i];

			b[m]=1;

		}

		else{

			b[m]++;

		}

	}

	for(register int i=1;i<=m;i++){

		if(b[i]>=c[i]){

			ans+=b[i]-c[i];

		}

		else ans+=b[i];

	}

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;







map<int, int>mp;

int ara[100009];

int main()

{

	int n;

	scanf("%d",&n);



	for(int i=0;i<n;i++)

	{

		scanf("%d",&ara[i]);

		mp[ara[i]]++;

	}





	int tot=0;

	for(int i=0;i<n;i++)

	{

        int x=ara[i];



		if(mp[x]>=x)

        tot+= mp[x]-x;

        else

			tot+=mp[x];



        mp[x]=x;



	}





	printf("%d\n",tot);



}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;



int a[100005],b[100005],c[100005];



int main(){

	int ans=0;

	int n;

	scanf("%d",&n);

	for(register int i=1;i<=n;i++){

		scanf("%d",&a[i]);

	}

	int m=0;

	sort(a+1,a+n+1);

	for(register int i=1;i<=n;i++){

		if(a[i]!=c[m]){

			c[++m]=a[i];

			b[m]=1;

		}

		else{

			b[m]++;

		}

	}

	for(register int i=1;i<=m;i++){

		if(b[i]>=c[i]){

			ans+=b[i]-c[i];

		}

		else ans+=b[i];

	}

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int cnt[100009];



int main()

{

    //cout<<cnt[1000000000]<<endl;



    int n;

    scanf("%d",&n);

    int a[100009];

    int uniq[100009];



    int i=0;

    for( i=0; i<n; i++)

    {

        scanf("%d",&a[i]);

        //cnt[a[i]]++;

    }



    sort(a,a+n);

    int j =0;

    cnt[j]=1;

    uniq[j] = a[0];

    for( i=1; i<n; i++)

    {

        if(a[i]!=a[i-1])

        {

            j++;

            cnt[j]=1;

            uniq[j]=a[i];

        }

        else cnt[j]++;

    }

    int ans =0;

    i=0;

    for(int i=0; i<=j; i++)

    {

        if(cnt[i]<uniq[i]) ans+=cnt[i];

        else if(cnt[i]>uniq[i]) ans+= cnt[i]-uniq[i];

    }

    printf("%d\n",ans);

    //main();



    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;



int a[100005],b[100005],c[100005];



int main(){

	int ans=0;

	int n;

	scanf("%d",&n);

	for(register int i=1;i<=n;i++){

		scanf("%d",&a[i]);

	}

	int m=0;

	sort(a+1,a+n+1);

	for(register int i=1;i<=n;i++){

		if(a[i]!=c[m]){

			c[++m]=a[i];

			b[m]=1;

		}

		else{

			b[m]++;

		}

	}

	for(register int i=1;i<=m;i++){

		if(b[i]>=c[i]){

			ans+=b[i]-c[i];

		}

		else ans+=b[i];

	}

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main() {



  //  freopen ("in.txt", "r", stdin);



    int n;

    cin >> n;



    map < long, long > cnt;



    long a[n];

    vector < long > lst;



    for (int i=0; i<n; i++) {



        cin >> a[i];

        if(cnt[a[i]]==0) lst.push_back(a[i]);

        cnt[a[i]]++;

    }

    long lagbe = 0;

    for (int i=0; i<(int)lst.size(); i++) {

        int v = lst[i];

        if(v!=cnt[v]) {

            if(cnt[v]>v) {

                lagbe += cnt[v]-v;

            }

            else lagbe += cnt[v];

        }

    }



    cout << lagbe << endl;





    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;



int a[100005],b[100005],c[100005];



int main(){

	int ans=0;

	int n;

	scanf("%d",&n);

	for(register int i=1;i<=n;i++){

		scanf("%d",&a[i]);

	}

	int m=0;

	sort(a+1,a+n+1);

	for(register int i=1;i<=n;i++){

		if(a[i]!=c[m]){

			c[++m]=a[i];

			b[m]=1;

		}

		else{

			b[m]++;

		}

	}

	for(register int i=1;i<=m;i++){

		if(b[i]>=c[i]){

			ans+=b[i]-c[i];

		}

		else ans+=b[i];

	}

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;



const int MAX_N = 1e5 + 5;

int n, ans;

int Arr[MAX_N];

int cnt[MAX_N];



int main() {

	ios::sync_with_stdio(false), cin.tie(0);

	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> Arr[i];

		if (n < Arr[i]) {

			i--;

			n--;

			ans++;

		}

	}



	for (int i = 0; i < n; i++)

		cnt[Arr[i]]++;



	for (int i = 1; i < MAX_N; i++)

		if (cnt[i] < i)

			ans += cnt[i];

		else

			ans += (cnt[i] - i);



	cout << ans << "\n";

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 5;

int n, a[maxn];

int cnt[maxn];

int ans = 0;

int main() {

	cin >> n;

	for(int i = 0; i < n; i++) {

		cin >> a[i];

		if(a[i] > n)

			ans++;

		else

			cnt[a[i]]++;

	}

	for(int i = 1; i <= n; i++) {

		if(cnt[i] >= i)

			ans += cnt[i] - i;

		else

			ans += cnt[i];

	}

	cout << ans;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define Would

#define you

#define please



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);



	

	int N;

	cin >> N;



	map<int, int> A;



	rep(i, N) {

		int a;

		cin >> a;

		A[a]++;

	}



	int kotae = 0;

	for (auto itr: A) {

		while (itr.second != 0 && itr.second != itr.first) {

			itr.second--;

			kotae++;

		}

	}

	co(kotae);



	Would you please return 0;

}

// Optimized solution to the same problem (faster):
//#include<bits/stdc++.h>

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



int A[100001];

int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint();

	int kotae = 0;

	rep(i, N) {

		int a = getint();

		if (a <= 100000) A[a]++;

		else kotae++;

	}

	rep1(i, 100000) {

		if (A[i] >= i) kotae += A[i] - i;

		else kotae += A[i];

	}

	printf("%d", kotae);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



#define rep(i, N) for (ll i = 0; i < N; i++)

#define rep1(i, N) for (ll i = 1; i <= N; i++)

#define MOD (int)1e9+7;



using ll = long long;

using namespace std;



int main() {

    int N;

    cin >> N;

    int cnt[(int)1e5+3] = {0};

    int ans = 0;



    rep(i, N) {

        int a;

        cin >> a;

        if(a > N) ans++;

        else cnt[a]++;

    }

    

    rep1(i, N) {

        if(cnt[i] > i) ans += cnt[i] - i;

        else if(cnt[i] < i) ans += cnt[i];

    }



    cout << ans << "\n";

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define FOR(i, l, r) for(ll i = l; i < r; i++)

#define rep(i, N) FOR(i, 0, N)

using namespace std;



typedef long long ll;

typedef pair<int,int> P;

typedef vector<int> vi;

typedef vector<ll> vl;

const ll MOD = round(1e9+7);



int main() {

    int N; cin >> N;

    vi A(N); rep(i,N) cin >> A[i];

    sort(A.begin(), A.end());

    A.emplace_back(-1);

    int ans = 0, tmp = 0, cnt = 0;

    rep(i,N+1){

        if(A[i] != tmp){

            ans += (cnt >= tmp?cnt - tmp:cnt);

            tmp = A[i];

            cnt = 1;

        }else{

            cnt++;

        }

    }



    cout << ans << endl;

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main(){

  int n;

  cin >> n;

  int a[n];

  for(int i=0;i<n;i++) cin >> a[i];

  int ans=0;

  int count[100001];

  for(int i=0;i<100001;i++) count[i]=0;

  for(int i=0;i<n;i++){

    if(a[i]>100000){

      ans++;

    }

    else{

      count[a[i]]++;

    }

  }

  for(int i=0;i<100001;i++){

    if(count[i]>=i){

      ans+=count[i]-i;

    }

    else{

      ans+=count[i];

    }

  }

  cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <string>

#include <queue>

#include <stack>

#include <set>

#include <map>

#include <iomanip>

#include <utility>

#include <tuple>

#include <functional>

#include <bitset>

#include <cassert>

#include <complex>

#include <stdio.h>

#include <time.h>

#include <numeric>

#include <random>

#include <unordered_map>

#include <unordered_set>

#define all(a) a.begin(),a.end()

#define rep(i, n) for (ll i = 0; i < (n); i++)

#define pb push_back

#pragma GCC optimize("O3")

#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef pair<ll, ll> P;

typedef complex<ld> com;

constexpr int inf = 1000000010;

constexpr ll INF = 1000000000000000010;

constexpr ld eps = 1e-12;

constexpr ld pi = 3.141592653589793238;

template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }

template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }





signed main() {

	cin.tie(0);

	ios::sync_with_stdio(false);

	cout << fixed << setprecision(20);



	int n;

	cin >> n;

	vector<int> a(n), cnt(n + 1);

	int ans = 0;

	rep(i, n) {

		cin >> a[i];

		if (a[i] > n) ans++;

		else cnt[a[i]]++;

	}

	rep(i, n + 1) {

		if (cnt[i] < i) ans += cnt[i];

		else ans += cnt[i] - i;

	}

	cout << ans << '\n';

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    long long n,a[100010]={0},t=0,s;

    cin>>n;

    for(int i=1;i<=n;i++)

        cin>>a[i];

    for(int i=1;i<=n;i++)

    {

        if(a[i]!=0)

        {

            s=0;

            if(a[i]<=n)

            {

                for(int j=1;j<=n;j++)

                {

                    if(a[j]!=0&&a[j]==a[i]&&j!=i)

                    {

                        a[j]=0;

                        s++;

                    }

                }

                s++;

                if(s!=a[i])

                {

                    if(s>a[i]) t+=s-a[i];

                    else t+=s;

                }

            }

            else t++;

        }

    }

    cout<<t<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<algorithm>

#define N 100000+5

using namespace std;

int n,a[N],ans,f;

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	sort(a+1,a+1+n);

	for(int i=1;i<=n;i++)

	{

		f++;

		if(a[i] != a[i+1])

		{

			if(f < a[i]) ans += f;

			if(f > a[i]) ans += f-a[i];

			f = 0;

		}

	}

	printf("%d\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main()

{

    long int n,ar[100005],check[100005]={0},i,c=0;

    cin>>n;

    for(i=0;i<n;i++)

    {

        cin>>ar[i];

        if(ar[i]>100000)

        {

            c++;

        }

        else if(ar[i]<=100000)

        {

            check[ar[i]]++;

        }

    }



    for(i=0;i<=100000;i++)

    {

        if(check[i]>i)

        {

            c = c+(check[i]-i);

        }

        else if(check[i]<i)

        {

            c = c+check[i];

        }

    }

    cout<<c<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



const int N=1e5 +3;

int a[N];

map<int, int> mp;



int main(){



    int n;

    scanf("%d", &n);

    for(int i=0; i<n; ++i){

        scanf("%d", a+i);

        ++mp[a[i]];

    }



    int ans=0;

    for(auto i:mp){

        if(i.second<i.first)

            ans+=i.second;

        else

            ans+=i.second-i.first;

    }



    printf("%d", ans);



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



const int N = 1e5 + 100;



int n, num, ans, cnt[N];



int main() {

	ios::sync_with_stdio(false), cin.tie(0);

	cin >> n;

	while(n--) {

		cin >> num;

		if(num >= N)

			ans++;

		else

			cnt[num]++;

	}

	for (int i = 1; i < N; i++)

		if(cnt[i] < i)

			ans += cnt[i];

		else

			ans += cnt[i] - i;

	cout << ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



const int N=1e5 +3;

int a[N];

map<int, int> mp;



int main(){



    int n;

    scanf("%d", &n);

    for(int i=0; i<n; ++i){

        scanf("%d", a+i);

        ++mp[a[i]];

    }



    int ans=0;

    for(auto i:mp){

        if(i.second<i.first)

            ans+=i.second;

        else

            ans+=i.second-i.first;

    }



    printf("%d", ans);



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <iomanip>

#include <cmath>

#include <string>

#include <cstring>

#include <algorithm>

#include <vector>

#include <sstream>

#include <set>

#include <queue>

#include <stack>

#include <cctype>

#include <map>

#include <climits>

#include <bitset>

using namespace std;

#define MATH_PI 3.14159265358979323846

int main(){

	ios::sync_with_stdio(false);

	map<int, int> mapNums;

	vector<int> arrNums;

	register int i;

	int n, nCount=0;

	cin >> n;

	for (i = 1; i <= n; ++i){

		int x;

		cin >> x;

		if (mapNums[x] == 0)

			arrNums.push_back(x);

		++mapNums[x];

	}

	for (i = 0; i < arrNums.size(); ++i){

		if (mapNums[arrNums[i]] >= arrNums[i])

			nCount += mapNums[arrNums[i]] - arrNums[i]; 

		else 

			nCount += mapNums[arrNums[i]];

	}

	cout << nCount << endl;

endapp:

	//system("pause > nul");

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<map>

#define F(a) for(register int (i)(0);(i)<(a);(i)++)

int n,a[100010];

std::map<int,int> m;

signed main()

{

	scanf("%d",&n);int t,now(0),ans(0);

	F(n)

	{

		scanf("%d",&t);

		if(!m[t])

		{

			a[now++]=t;

		}

		m[t]++;

	}

	F(now)

	{

		(ans+=m[a[i]])-=a[i]*(m[a[i]]>=a[i]);

	}

	return printf("%d\n",ans),0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int n,a[100001],x,ans;

int main()

{

	cin>>n;

	for(int i=1;i<=n;i++)

	{

		cin>>x;

		if(x>100000) ans++;

		else a[x]++;

	}

	for(int i=1;i<=100000;i++)

	{

		if(a[i]==0) continue;

		if(a[i]<i) ans+=a[i];

		else if(a[i]>i) ans+=a[i]-i;

	}

	cout<<ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <map>

using namespace std;

int a[100005];

map<int,int>f;

int main()

{

	int i,n,ans=0;

	scanf ("%d",&n);

	for (i=1; i<=n; i++) scanf ("%d",&a[i]),f[a[i]]++;

	for (i=1; i<=n; i++)

		if (f[a[i]]<a[i]) ans+=f[a[i]],f[a[i]]=a[i];

		else if (f[a[i]]>a[i]) ans+=(f[a[i]]-a[i]),f[a[i]]=a[i];

	printf ("%d\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int n,a[100010],b,ans;

int main()

{

	cin>>n;

	for(int i=0;i<n;i++)

	{

		cin>>b;

		if(b>100000)

		  ans++;

		else a[b]++;

	}

	for(int i=0;i<100001;i++)

	{

		if(a[i]>=i)

		  ans+=a[i]-i;

		else ans+=a[i];

	}

	cout<<ans;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define tin int

#define itn int

#define tni int

#define nit int

#define nti int

#define pritnf printf

#define scnaf scanf

#define retrun return

#define sizoef sizeof

#define ll long long

#define inl inline

#define br break

#define con continue

#define mst(a,b) memset(a,b,sizeof(a))

#define re register itn

#define fora(x,a,b) for(re x=a;x<=b;++x)

#define forb(x,a,b) for(re x=a;x>=b;--a)

#define infa 0x3f3f3f3f

#define infb 0x7fffffff

#define infc 1061109567

#define infd 0x7f

using namespace std;

#define maxa 100004

#define maxb 10004

#include<cstring>



tni num,x,n[maxa]={0},sum=0;



tin main()

{

	scanf("%d",&num);

	fora(i,1,num)

	{

		scanf("%d",&x);

		if(x>num)

		{

			++sum;

		}

		else

		{

			++n[x];

		}

	}

	//

	fora(i,1,num)

	{

		if(n[i]<i)

		{

			sum+=n[i];

		}

		else if(n[i]>i)

		{

			sum+=n[i]-i;

		}

	}

	//

	printf("%d\n",sum);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<iomanip>

#include<cmath>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<set>

#include<map>

#include<queue>

#include<stack>

#include<vector>

#include<cctype>

#define F(a,b,c) for(register int (a)(b);(a)<=(c);(a)++)

using namespace std;

int n;

map<int,int> m;

vector<int> v;

signed main()

{

	scanf("%d",&n);int tmp,ans(0);

	F(i,1,n){scanf("%d",&tmp);if(!m[tmp]){v.push_back(tmp);};m[tmp]++;}

	F(i,0,v.size()){ans+=(m[v[i]]-((m[v[i]]>=v[i])*v[i]));}

	printf("%d",ans);

	return putchar(10),0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define tin int

#define itn int

#define tni int

#define nit int

#define nti int

#define pritnf printf

#define scnaf scanf

#define retrun return

#define sizoef sizeof

#define ll long long

#define inl inline

#define br break

#define con continue

#define mst(a,b) memset(a,b,sizeof(a))

#define re register itn

#define fora(x,a,b) for(re x=a;x<=b;++x)

#define forb(x,a,b) for(re x=a;x>=b;--a)

#define infa 0x3f3f3f3f

#define infb 0x7fffffff

#define infc 1061109567

#define infd 0x7f

using namespace std;

#define maxa 100004

#define maxb 10004

#include<cstring>



tni num,x,n[maxa]={0},sum=0;



tin main()

{

	scanf("%d",&num);

	fora(i,1,num)

	{

		scanf("%d",&x);

		if(x>num)

		{

			++sum;

		}

		else

		{

			++n[x];

		}

	}

	//

	fora(i,1,num)

	{

		if(n[i]<i)

		{

			sum+=n[i];

		}

		else if(n[i]>i)

		{

			sum+=n[i]-i;

		}

	}

	//

	printf("%d\n",sum);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<map>

#include<cmath>

#include<stack>

#include<cstdio>

#include<queue>

#include<vector>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

map<int,int>a;

vector<int>q;

int n,ans;

int main(){

	scanf("%d",&n);

	for(int i=1;i<=n;i++){

        int x;

        scanf("%d",&x);

        if(!a[x])q.push_back(x);

        a[x]++;

	}

	int top=q.size();

	for(int i=0;i<top;i++){

        if(a[q[i]]>=q[i])ans+=a[q[i]]-q[i];

        else ans+=a[q[i]];

	}

	printf("%d\n",ans);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#define tin int

#define itn int

#define tni int

#define nit int

#define nti int

#define pritnf printf

#define scnaf scanf

#define retrun return

#define sizoef sizeof

#define ll long long

#define inl inline

#define br break

#define con continue

#define mst(a,b) memset(a,b,sizeof(a))

#define re register itn

#define fora(x,a,b) for(re x=a;x<=b;++x)

#define forb(x,a,b) for(re x=a;x>=b;--a)

#define infa 0x3f3f3f3f

#define infb 0x7fffffff

#define infc 1061109567

#define infd 0x7f

using namespace std;

#define maxa 100004

#define maxb 10004

#include<cstring>



tni num,x,n[maxa]={0},sum=0;



tin main()

{

	scanf("%d",&num);

	fora(i,1,num)

	{

		scanf("%d",&x);

		if(x>num)

		{

			++sum;

		}

		else

		{

			++n[x];

		}

	}

	//

	fora(i,1,num)

	{

		if(n[i]<i)

		{

			sum+=n[i];

		}

		else if(n[i]>i)

		{

			sum+=n[i]-i;

		}

	}

	//

	printf("%d\n",sum);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



map<int,int> m;

vector<int> v;



int main(){

    int n,ans;

    cin>>n;

    for(register int i=1;i<=n;++i){

        int x;

        cin>>x;

        if(m[x]==0) v.push_back(x);

        ++m[x];

    }

    for(register int i=0;i<v.size();++i) if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; else ans+=m[v[i]];

    cout<<ans;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#define tin int

#define itn int

#define tni int

#define nit int

#define nti int

#define pritnf printf

#define scnaf scanf

#define retrun return

#define sizoef sizeof

#define ll long long

#define inl inline

#define br break

#define con continue

#define mst(a,b) memset(a,b,sizeof(a))

#define re register itn

#define fora(x,a,b) for(re x=a;x<=b;++x)

#define forb(x,a,b) for(re x=a;x>=b;--a)

#define infa 0x3f3f3f3f

#define infb 0x7fffffff

#define infc 1061109567

#define infd 0x7f

using namespace std;

#define maxa 100004

#define maxb 10004

#include<cstring>



tni num,x,n[maxa]={0},sum=0;



tin main()

{

	scanf("%d",&num);

	fora(i,1,num)

	{

		scanf("%d",&x);

		if(x>num)

		{

			++sum;

		}

		else

		{

			++n[x];

		}

	}

	//

	fora(i,1,num)

	{

		if(n[i]<i)

		{

			sum+=n[i];

		}

		else if(n[i]>i)

		{

			sum+=n[i]-i;

		}

	}

	//

	printf("%d\n",sum);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define rpt(n) for(register int ttxyc=0;ttxyc<n;++ttxyc)//宏定义

using namespace std;

int n,a,ans;map<int,int>m;

main()

{

    scanf("%d",&n);

    rpt(n)

	{

		scanf("%d",&a);

		if(m.count(a))++m[a];

		else m[a]=1;

	}

	for(map<int,int>::iterator i=m.begin();i!=m.end();++i)

	{

		pair<int,int>now=*i;

		if(now.first>now.second)ans+=now.second;

		else ans+=now.second-now.first;

	}

	printf("%d\n",ans);

}/**/

// Optimized solution to the same problem (faster):
#include<cstdio>

#define tin int

#define itn int

#define tni int

#define nit int

#define nti int

#define pritnf printf

#define scnaf scanf

#define retrun return

#define sizoef sizeof

#define ll long long

#define inl inline

#define br break

#define con continue

#define mst(a,b) memset(a,b,sizeof(a))

#define re register itn

#define fora(x,a,b) for(re x=a;x<=b;++x)

#define forb(x,a,b) for(re x=a;x>=b;--a)

#define infa 0x3f3f3f3f

#define infb 0x7fffffff

#define infc 1061109567

#define infd 0x7f

using namespace std;

#define maxa 100004

#define maxb 10004

#include<cstring>



tni num,x,n[maxa]={0},sum=0;



tin main()

{

	scanf("%d",&num);

	fora(i,1,num)

	{

		scanf("%d",&x);

		if(x>num)

		{

			++sum;

		}

		else

		{

			++n[x];

		}

	}

	//

	fora(i,1,num)

	{

		if(n[i]<i)

		{

			sum+=n[i];

		}

		else if(n[i]>i)

		{

			sum+=n[i]-i;

		}

	}

	//

	printf("%d\n",sum);

	return 0;

}

// Fastest known solution for this problem: