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

using namespace std;

const int maxx = 2e5 + 7;

const int Mod = 1e9 + 7;

typedef long long ll;

ll n;

int a, b;

ll fac[maxx], inv[maxx];



ll qwe(ll x, int y) {

	ll res = 1ll;

	while(y) {

		if(y & 1) res = res * x % Mod; 

		x = x * x % Mod;

		y >>= 1; 

	}

	return res;

}



ll Com(ll n, ll m) {

	ll res = 1ll;

	for(ll i = n; i >= n - m + 1; i--) res = res * i % Mod;

	return res * inv[m] % Mod;

}



int main() {

	fac[0] = inv[0] = 1; 

	for(int i = 1; i <= maxx; i++) fac[i] = fac[i - 1] * i % Mod;

	inv[maxx] = qwe(fac[maxx], Mod - 2);

	for(int i = maxx - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % Mod;

	scanf("%lld %d %d", &n, &a, &b);

	ll ans = qwe(2, n) - 1;

	ans = (ans - Com(n, a) + Mod) % Mod;

	ans = (ans - Com(n, b) + Mod) % Mod;

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

	return 0;

}

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

using namespace std;

typedef long long LL;

const LL Mod = 1e9 + 7;

LL n, a, b, ans;



LL qwe(LL a, LL n) { //快速幂

	LL res = 1LL;

	while(n) {

		if(n & 1) res = res * a % Mod;

		a = a * a % Mod;

		n >>= 1LL;

	}

	return res % Mod;

}



LL C(LL n, LL m) { //组合数

	if(m < n - m) m = n - m;

	LL x = 1LL;

	for(LL i = m + 1; i <= n; i++) x = x * i % Mod;

	LL y = 1LL;

	for(LL i = 1; i <= n - m; i++) y = y * i % Mod;

	return x * qwe(y, Mod - 2) % Mod;

	//除法取模只需将除法变乘法即可, 也就是用被除数去乘以除数的乘法逆元

	//求乘法逆元用费马小定理: 当模Mod为素数, x的逆元为qwe(x, Mod - 2)

}



int main() {

	cin >> n >> a >> b;

	ans = ((qwe(2LL, n) - C(n, a) - C(n, b) - 1) % Mod + Mod) % Mod;

	cout << ans << endl;

    return 0;

}



/*

c(n, 1) + ... + c(n, n)

c(n, 0) + ... + c(n, n) = 2 ^ n

=> ans = (2 ^ n) - C(n, a) - C(n, b) - 1

减去一束也不选的情况

*/

// Fastest known solution for this problem:
// Original C++ solution (slower):


#include <iostream>

#include <string>

#include <algorithm>

#include <cmath>





using namespace std;

using LLint = long long int;



LLint ModPow(LLint j,LLint k,LLint l){

	//(j^k)/mod l を計算

	if(k==0) return 1%l;

	else if(k%2==0){

		LLint t=ModPow(j,k/2,l);//k/2乗したもの

		return t*t%l;

	}

	else return (j%l)*ModPow(j,k-1,l)%l;

}



LLint Combi(LLint a,LLint b,LLint M){

	LLint UP,DOWN;

	UP=DOWN=1;

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

		UP = UP*((a-i)%M)%M;

		DOWN = DOWN*((i+1)%M)%M;

	}

	return (UP*ModPow(DOWN,M-2,M))%M;

}







const LLint Mod = 1000000007;



int main() {

	int n,a,b;

	cin>>n>>a>>b;

	LLint ALL = ModPow(2,n,Mod);



	LLint A;

	A=Combi(n,a,Mod);



	LLint B;

	B=Combi(n,b,Mod);



	cout<< (((ALL-1-A-B)%Mod)+Mod)%Mod<<endl;



	return 0;

}

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

#include <string>

#include <algorithm>

#include <cmath>



using namespace std;

using llint = long long int ;



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

// c 回繰り返す



const llint mod = 1000000007;

//mod　10^9 + 7





///////////////////////便利？な関数///////////////////////

llint Pow_Mod(llint n,llint p,llint m){

    //n^p mod　の繰り返し二乗法

    if(p==0) return 1%m;

    else if(p%2==0){

        llint kakeru = Pow_Mod(n,p/2,m);

        return kakeru*kakeru%m;

    }

    else return n%m*Pow_Mod(n,p-1,m)%m;

}



llint Conbi(llint x,llint y,llint m){

    //xCy mod を求める

    llint UP,DOWN;

    UP=DOWN=1%m;

    rep(i,y){

        UP=UP*(x-i)%m;

        DOWN=DOWN*(i+1)%m;

    }

    return UP*Pow_Mod(DOWN,m-2,m)%m;

    //mは素数がいい

}









int main(){

    

    int n,a,b;

    cin>>n>>a>>b;



    int ALL=Pow_Mod(2,n,mod);

    int AB=Conbi(n,a,mod)+Conbi(n,b,mod);



    cout<<((ALL-AB-1)%mod+mod)%mod<<endl;







    return 0;

}




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

using namespace std;

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

typedef long long ll;

typedef pair<int,int> P;

long modding = pow(10, 9) + 7;



ll saisyo(int n){

  if(n==0)

    return 1;

  ll x = saisyo(n / 2);

  x %= modding;

  x *= x;

  x %= modding;

  if(n%2==1) x*=2;

  x %= modding;

  return x;

} 



ll modpow(ll a,ll n){

    ll res = 1;

    while(n > 0){

        if(n&1) res = res * a % modding;

        a = a * a % modding;

        n >>= 1;

    }

    return res;

}



ll modinv(ll x){

    return modpow(x,modding-2);

}

 

long comb(ll   n,ll a){

  ll  x = 1, y = 1;

  rep(i,a){

    x *= (n - i);

    y *= i+1;

    x %= modding;

    y %= modding;

  }



  return x*modinv(y)%modding;

}

int main (){

  long n, a, b;

  cin >> n >> a >> b;

  long ans = saisyo(n);

  ans -= 1;

  ans -= comb(n, a);

  ans -= comb(n, b);

  ans %= modding;

  while(ans<0)

    ans += modding;

  cout << ans << endl;

}

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

using namespace std;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;

typedef pair<int, int> P;

const int INF = 100100100;

const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

long long longpow(long long a, long long b) {

  if (b == 0) return 1;

  if (b == 1) return a%MOD;

  if (b % 2 == 1) return (a  * longpow(a, b - 1)) % MOD;

  ll t = longpow(a, b / 2)%MOD;

  return (t * t) % MOD;

}

long long modpow(long long a, long long n) {

  long long res = 1;

  long long mod = n + 2;

  while (n > 0) {

    if (n & 1) res = res * a % mod;

    a = a * a % mod;

    n >>= 1;

  }

  return res;

}

long long inverse(long long x, long long modding) {

  return modpow(x, modding - 2);

}

ll comb(ll r, ll a) {

  ll R = r;

  REP(i, a - 1) {

    r--;

    R *= r;

    R %= MOD;

  }

  ll A = 1;

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

    A *= i;

    A %= MOD;

  }

  return R * inverse(A, MOD) % MOD;

}





int main() {

  ll n, a, b;

  cin >> n >> a >> b;

  ll ans = longpow(2,n) - 1;

  ans -= comb(n, a);

  ans -= comb(n, b);

  while (ans < 0) {

    ans += MOD;

  }

  cout << ans << endl;

}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const int iinf = 1 << 28;

const long long llinf = 1ll << 60;

const double PI = 3.14159265;



ll inv[200001], invf[200001];



ll exp(ll a, ll b) {

    if (b == 0LL) return 1LL;

    if (b == 1LL) return a;

    ll ans = exp(a, b>>1);

    ans = (ans * ans) % MOD;

    if (b&1LL) ans = (ans * a) % MOD;

    return ans;

}



void work() {

    ll n, a, b; cin>>n>>a>>b;

    ll ans = (exp(2LL, n) - 1LL) % MOD;

    

    // a

    ll d1 = max(a, n-a), d2 = min(a, n - a);

    ll fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    inv[1] = 1LL;

    invf[0] = invf[1] = 1LL;

    ll m = d2 + 1LL;

    for(ll i = 2LL; i < m; ++i) {

        inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

        invf[i] = (inv[i] * invf[i-1LL]) % MOD;

    }

    ll na = (fact_n * invf[d2]) % MOD;

    ans = (ans - na + MOD) % MOD;

    //cout << na << endl;



    // if (b == n-a) {

    //     cout << ans << endl;

    //     return;

    // }



    // b

    d1 = max(b, n-b), d2 = min(b, n - b);

    fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    inv[1] = 1LL;

    invf[0] = invf[1] = 1LL;

    m = d2 + 1LL;

    for(ll i = 2LL; i < m; ++i) {

        inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

        invf[i] = (inv[i] * invf[i-1LL]) % MOD;

    }

    ll nb = (fact_n * invf[d2]) % MOD;

    ans = (ans - nb + MOD) % MOD;

    //cout << nb << endl;



    cout << ans << endl;

}



int main() {

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    work();



    return 0;

}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const int iinf = 1 << 28;

const long long llinf = 1ll << 60;

const double PI = 3.14159265;



ll exp(ll a, ll b) {

    if (b == 0LL) return 1LL;

    if (b == 1LL) return a;

    ll ans = exp(a, b>>1);

    ans = (ans * ans) % MOD;

    if (b&1LL) ans = (ans * a) % MOD;

    return ans;

}



void work() {

    ll n, a, b; cin>>n>>a>>b;

    ll ans = (exp(2LL, n) - 1LL) % MOD;

    

    // a

    ll d1 = max(a, n-a), d2 = min(a, n - a);

    ll fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    ll invff = 1LL;

    for (ll i = d2; i > 1; --i) invff = (invff * i) % MOD;

    ll na = (fact_n * exp(invff, MOD-2LL)) % MOD;

    ans = (ans - na + MOD) % MOD;



    // b

    d1 = max(b, n-b), d2 = min(b, n - b);

    fact_n = 1LL;

    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;



    invff = 1LL;

    for (ll i = d2; i > 1; --i) invff = (invff * i) % MOD;

    ll nb = (fact_n * exp(invff, MOD-2LL)) % MOD;

    ans = (ans - nb + MOD) % MOD;



    cout << ans << endl;

}



int main() {

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    work();



    return 0;

}


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

using namespace std;



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



typedef long long ll;

typedef pair<int, int> P;



const int MAX = 1e5 + 5;

const int INF = 1001001001;

const int MOD = 1e9 + 7;



// x の n 乗 x^n を計算する

long long mod_pow(long long x, long long n, int M=1000000007) {

  long long ret = 1;

  while(n) {

    if(n & 1) (ret *= x) %= M;

    (x *= x) %= M;

    n >>= 1;

  }

  return ret;

}



// a の逆元 a^{-1} を計算する

long long inv(long long a, int M=1000000007) {

    long long b = M, u = 1, v = 0;

    while (b) {

        long long t = a / b;

        a -= t * b; swap(a, b);

        u -= t * v; swap(u, v);

    }

    u %= M;

    if (u < 0) u += M;

    return u;

}



// 二項係数 nCr を計算する

long long com(long long n, long long r, int M=1000000007) {

    long long a = 1, b = 1;

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

        a *= n - (i-1), b *= i;

        a %= M, b %= M;

    }

    return a * inv(b) % M;

}



int main(){

    int n, a, b;

    cin >> n >> a >> b;



    ll ans = mod_pow(2,n) - 1 - com(n,a) - com(n,b);

    while (ans < 0) ans += MOD;



    cout << ans << endl;

}

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

using namespace std;



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



typedef long long ll;

typedef pair<int, int> P;



const int MAX = 1e5 + 5;

const int INF = 1001001001;

const int MOD = 1e9 + 7;



struct mint {

    long long x;

    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }

    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }

    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }

    mint operator+(const mint& a) const { return mint(x) += a; }

    mint operator-(const mint& a) const { return mint(x) -= a; }

    mint operator*(const mint& a) const { return mint(x) *= a; }



    // for prime mod

    mint inv() const {

        long long a = x, b = MOD, u = 1, v = 0;

        while (b) {

            long long t = a / b;

            a -= t * b; swap(a, b);

            u -= t * v; swap(u, v);

        }

        return mint(u);

    }

    mint& operator/=(const mint& a) { return *this *= a.inv(); }

    mint operator/(const mint& a) const { return mint(x) /= a; }

};

ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }



long long mod_pow(long long x, long long n, int M=1000000007) {

    long long ret = 1;

    while(n) {

        if(n & 1) (ret *= x) %= M;

        (x *= x) %= M;

        n >>= 1;

    }

    return ret;

}



int main(){

    int n, a, b;

    cin >> n >> a >> b;



    mint ans = mod_pow(2, n) - 1;

    mint x = 1, y = 1;

    rep(i, a) {

        x *= n - i;

        y *= i + 1;

    }

    ans -= x / y;

    x = y = 1;

    rep(i, b) {

        x *= n - i;

        y *= i + 1;

    }

    ans -= x / y;

    cout << ans << endl;

}

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

#include <iostream>

#pragma warning(disable : 4996)

using namespace std;

int H, W, R, C; string s[1000], t[1000]; unsigned long long power[1001], h1[1000][1000], h2[1000];

int main() {

	scanf("%d%d", &H, &W);

	for (int i = 0; i < H; i++) cin >> s[i];

	scanf("%d%d", &R, &C);

	for (int i = 0; i < R; i++) cin >> t[i];

	power[0] = 1;

	for (int i = 1; i <= 1000; i++) power[i] = power[i - 1] * 257;

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

		unsigned long long val = 0;

		for (int j = 0; j < C; j++) val = val * 257 + s[i][j]; h1[i][0] = val;

		for (int j = C; j < W; j++) val = val * 257 + s[i][j] - power[C] * s[i][j - C], h1[i][j - C + 1] = val;

	}

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

		for (int j = 0; j < C; j++) h2[i] = h2[i] * 257 + t[i][j];

	}

	for (int i = 0; i <= H - R; i++) {

		for (int j = 0; j <= W - C; j++) {

			bool flag = true;

			for (int k = i; k < i + R; k++) {

				if (h1[k][j] != h2[k - i]) {

					flag = false; break;

				}

			}

			if (flag) {

				printf("%d %d\n", i, j);

			}

		}

	}

	return 0;

}

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

int H, W, R, C; char s[1001][1007], t[1001][1007];

unsigned long long pw1, pw2, h1[1001][1007], h2[1001][1007], h3[1001];

int main() {

	scanf("%d%d", &H, &W);

	for(int i = 0; i < H; i++) scanf("%s", s[i]);

	scanf("%d%d", &R, &C); pw1 = 1, pw2 = 1;

	for(int i = 0; i < R; i++) scanf("%s", t[i]), pw2 *= 1000000007;

	for(int i = 0; i < C; i++) pw1 *= 257;

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

		unsigned long long w = 0;

		for(int j = 0; j < C; j++) w = w * 257 + s[i][j]; h1[i][0] = w;

		for(int j = C; j < W; j++) w = w * 257 + s[i][j] - pw1 * s[i][j - C], h1[i][j - C + 1] = w;

	}

	for(int i = 0; i <= W - C; i++) {

		unsigned long long w = 0;

		for(int j = 0; j < R; j++) w = w * 1000000007 + h1[j][i]; h2[0][i] = w;

		for(int j = R; j < H; j++) w = w * 1000000007 + h1[j][i] - pw2 * h1[j - R][i], h2[j - R + 1][i] = w;

	}

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

		for(int j = 0; j < C; j++) h3[i] = h3[i] * 257 + t[i][j];

	}

	unsigned long long h4 = 0;

	for(int i = 0; i < R; i++) h4 = h4 * 1000000007 + h3[i];

	for(int i = 0; i <= H - R; i++) { 

		for(int j = 0; j <= W - C; j++) {

			if(h2[i][j] == h4) printf("%d %d\n", i, j);

		}

	}

}

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

using namespace std;

typedef long long ll;

#define MAX_N 100005

ll mod=1e9+7;



ll mul(ll a,ll b){

  return (a*b)%mod;

}



int bit[MAX_N];

void add(int i,int x){

  i++;



  while(i<MAX_N){

    bit[i]+=x;

    i+=(i&-i);

  }

}



int sum(int i){

  i++;



  int res=0;

  while(i){

    res+=bit[i];

    i-=(i&-i);

  }

  return res;

}



ll N,R,a,b;

ll fact[MAX_N];

int t[MAX_N];



int main(){

  fact[0]=1;

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

    fact[i]=mul(fact[i-1],i);



  while(1){

    scanf("%lld",&N);

    if(N==0)break;

    scanf("%lld",&R);

    memset(bit,0,sizeof(bit));

    for(int i=0;i<N;i++)t[i]=i;



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

      scanf("%lld %lld",&a,&b);

      a--,b--;

      swap(t[a],t[b]);

    }



    ll ans=0;

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

      ll num=t[i];

      ll cnt=num-sum(num);

      ans+= mul(fact[N-1-i],cnt);

      ans%=mod;

      add(t[i],1);

    }



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

  }

  return 0;

}

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

using namespace std;

#define int long long

struct BIT{

  vector<int> bit;

  int n;

  BIT(){init();}

  BIT(int n):n(n){init();}

  void init(){

    bit.clear();

    bit.resize(n+1,0);

  }

  int sum(int i){

    int s=0;

    while(i>0){

      s+=bit[i];

      i-=i&-i;

    }

    return s;

  }

  void add(int i,int x){

    while(i<=n){

      bit[i]+=x;

      i+=i&-i;

    }

  }

};

int MOD=1000000007LL;

int s[114514],t[114514];

int fact[114514];

void init(int mod){

  fact[0]=fact[1]=1;

  for(int i=2;i<114514;i++)

    fact[i]=(fact[i-1]*i)%MOD;

}

signed main(){

  int n;

  init(MOD);

  while(cin>>n,n){

    BIT bit(n);

    for(int i=0;i<n;i++) s[i]=i+1;

    int r;

    cin>>r;

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

      int a,b;

      cin>>a>>b;

      a--;b--;

      swap(s[a],s[b]);

    }

    for(int i=n-1;i>=0;i--){

      t[i]=bit.sum(s[i]);

      bit.add(s[i],1);

    }

    int ans=0;

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

      (ans+=t[i]*fact[n-1-i])%=MOD;

    }

    cout<<ans<<endl;

  }

  return 0;

}

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

using namespace std;

#define loop(i,L,R) for(int i=(L);i<=(R);i++)

#define rept(i,L,R) for(int i=(L);i<(R);i++)

#define isc(n) scanf("%d",&n)

#define llsc(n) scanf("%lld",&n)

#define dsc(n) scanf("%lf",&n)

#define enl cout<<endl

#define pb(x) push_back(x)

#define xx first

#define yy second

typedef long long ll;

typedef pair<int,int>PI;

typedef pair<pair<int,int>,int>PII;



map<int,int>a;

int main()

{

    int n,t;

    cin>>n;

    rept(i,0,n){cin>>t;a[t]++;}

    ll ans=0;

    for(auto i:a)

    {

        if(i.xx>i.yy)ans+=i.yy;

        else ans+=min((i.yy-i.xx),i.yy);

    }

    cout<<ans<<endl;

	return 0;

}




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

#include<algorithm>

using namespace std;

inline int read()

{

	int s=0;

    char c=getchar();

    while(c<'0' || c>'9')c=getchar();

    while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+c-48,c=getchar();

    return s;

}

int n,a[100005],ans;

int main()

{

	n=read();

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

		a[i]=read();

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

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

	{

		int t=i;

		while(a[t+1]==a[i] && t+1<=n)  t++;

		int cnt=t-i+1;

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

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

		i=t;

	}

	printf("%d",ans);

	return 0;

}

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

using namespace std;



int main()

{

    int n,i,c=0,f,x;

    scanf("%d",&n);

    int a[n];

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

    sort(a,a+n);

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

    {

        f = 0;

        x = a[i];

        while(1)

        {

            if(i>=n)    break;

            else if(a[i]!=x)

            {

                i--;

                break;

            }

            i++;

            f++;

        }

        if(f<x)    c += f;

        else if(f>x)    c += (f-x);

    }

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

    return  0;

}


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

#include<algorithm>

using namespace std;

inline int read()

{

	int s=0;

    char c=getchar();

    while(c<'0' || c>'9')c=getchar();

    while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+c-48,c=getchar();

    return s;

}

int n,a[100005],ans;

int main()

{

	n=read();

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

		a[i]=read();

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

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

	{

		int t=i;

		while(a[t+1]==a[i] && t+1<=n)  t++;

		int cnt=t-i+1;

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

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

		i=t;

	}

	printf("%d",ans);

	return 0;

}

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

using namespace std;



const int MAXN = 1e5 + 10;

int cnt[MAXN], n, ans;



int main() {

	cin >> n;

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

		int a;

		cin >> a;

		if (a > 1e5)

			ans++;

		else

			cnt[a]++;

	}

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

		if (cnt[i] < i)

			ans += cnt[i];

		else

			ans += cnt[i] - i;

	cout << ans;

}

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

using namespace std;

long long n,a[100005],ans;

vector <long long> v;

int main()

{

	cin>>n;

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

	{

		cin>>a[i];

	}

	sort(a,a+n);

	/*v.push_back(a[0]);

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

	{

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

			v.push_back(a[i]);

	}*/

	int cur=1;

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

	{

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

		{

			cur++;

		}

		else

		{

			if(cur<a[i-1])

				ans+=cur;

			cur=1;

		}

		if(cur>a[i])

		{

			ans+=(cur-a[i]);

			cur=a[i];

		}

	}

	if(cur<a[n-1])

		ans+=cur;

	cout<<ans<<"\n";

	return 0;

}




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

#include <cmath>

#include <algorithm>



int c[100001];



int main() {

  long long int n;

  long long int count = 0;

  std::cin >> n;

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

    c[i] = 0;

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

    int x = 0;

    std::cin >> x;

    if (x >= 100001) {

      count++;

      continue;

    }   

    c[x]++;

  }

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

    count += (c[i] < i) ? c[i]: c[i] - i;

  }

  std::cout << count << std::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;



int a[100005];



int in()

{

    int a;

    scanf("%d",&a);

    return a;

}



int main()

{

    int n=in(),ans=0;

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

    {

        int aa=in();

        if(aa>100000)

            ans++;

        else

            a[aa]++;

    }

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

    {

        if(a[i]>i){

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

        }

        else if(a[i]<i)

        ans+=a[i];

    }

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

}


// 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> cnt;



int main()

{



    int n, x;



    scanf("%d", &n);



    int res = 0;



    while(n--){



        scanf("%d", &x);

        cnt[x]++;

    }



    for(map<int, int> ::iterator it = cnt.begin(); it!=cnt.end(); it++){



        int occ = it->second;



        int key = it->first;



        if(occ>key) res += (occ-key);

        else if(occ<key) res += occ;



    }



    cout<<res<<endl;







}


// 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: