Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(), YES, NO))
#define ECHO OUT(solve())
#define three(A, B, C) ((A) ? (B) : (C))
#define FOR(i, a, b) for (LL i = (a); i < (LL)(b); i++)
#define EFOR(i, a, b) for (LL i = (a); i <= (LL)(b); i++)
#define RFOR(i, a, b) for (LL i = (a); i >= (LL)(b); i--)
#define REP(i, b) FOR(i, zero, b)
#define EREP(i, b) EFOR(i, zero, b)
#define RREP(i, b) RFOR(i, zero, b)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a, b) OUT2(a, b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a, b) cout << (a) << " " << (b) << endl
#define int LL
#define zero 0LL
using namespace std;
template <typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template <typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template <typename T> inline bool middle(T a, T b, T c) {
  return b <= a && a <= c;
}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
inline void outputVI(VI x) {
  REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }
  OUT("");
}
const int SIZE = 3000;
const int SIZE2 = 5010;
const int SIZE3 = 400;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
string S;
ut N, M, K, X, L, W, H;
// ut A,B,C,D,E,F,G,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL a[SIZE], x[2], vals[SIZE], nums[SIZE], maps[SIZE2][SIZE2], answer = zero;
VI v[2];
map<int, int> times;
bool DP[4000][2];
bool able(int now) {}
signed main() {
  int N;
  cin >> N;
  REP(i, N) {
    cin >> a[i];
    times[a[i]] = times[a[i]] + 1;
  }
  int ans = 0;
  for (auto it = times.begin(); it != times.end(); ++it) {
    if ((*it).first <= (*it).second) {
      ans += (*it).second - (*it).first;
    } else {
      ans += (*it).second;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(), YES, NO))
#define ECHO OUT(solve())
#define three(A, B, C) ((A) ? (B) : (C))
#define FOR(i, a, b) for (LL i = (a); i < (LL)(b); i++)
#define EFOR(i, a, b) for (LL i = (a); i <= (LL)(b); i++)
#define RFOR(i, a, b) for (LL i = (a); i >= (LL)(b); i--)
#define REP(i, b) FOR(i, zero, b)
#define EREP(i, b) EFOR(i, zero, b)
#define RREP(i, b) RFOR(i, zero, b)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a, b) OUT2(a, b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a, b) cout << (a) << " " << (b) << endl
#define int LL
#define zero 0LL
using namespace std;
template <typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template <typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template <typename T> inline bool middle(T a, T b, T c) {
  return b <= a && a <= c;
}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
inline void outputVI(VI x) {
  REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }
  OUT("");
}
const int SIZE = 1e6;
const int SIZE2 = 5010;
const int SIZE3 = 400;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
string S;
ut N, M, K, X, L, W, H;
// ut A,B,C,D,E,F,G,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL a[SIZE], x[2], vals[SIZE], nums[SIZE], maps[SIZE2][SIZE2], answer = zero;
VI v[2];
map<int, int> times;
bool DP[4000][2];
bool able(int now) {}
signed main() {
  int N;
  cin >> N;
  REP(i, N) {
    cin >> a[i];
    times[a[i]] = times[a[i]] + 1;
  }
  int ans = 0;
  for (auto it = times.begin(); it != times.end(); ++it) {
    if ((*it).first <= (*it).second) {
      ans += (*it).second - (*it).first;
    } else {
      ans += (*it).second;
    }
  }
  cout << ans << endl;
  return 0;
}