prithivMLmods/Coder-Stat huggingface dataset:
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), s.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());

  string t;
  cin >> t;
  sort(t.begin(), t.end());
  reverse(t.begin(), s.end());

  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());

  string t;
  cin >> t;
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), s.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), s.end());
  reverse(t.begin(), s.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
print("Yes" if print(sorted(input())) < print(sorted(input())[::-1]) else "No")


Fixed submission:
print("Yes" if sorted(input()) < sorted(input())[::-1] else "No")
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), s.end(), greater<char>());
  if (s < t)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  do {
    do {
      if (s < t) {
        cout << "Yes" << endl;
        return 0;
      }
    } while (next_permutation(s.begin(), s.end()));
  } while (next_permutation(t.begin(), t.end()));
  cout << "No" << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
bool cmp(char a, char b) { return a > b; }
int main() {
  string s, t;
  cin >> s;
  cin >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), s.end(), cmp);
  if (s < t)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool cmp(char a, char b) { return a > b; }
int main() {
  string s, t;
  cin >> s;
  cin >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), cmp);
  if (s < t)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  string s, t;
  cin >> s >> t;
  do {
    do {
      if (s < t)
        return cout << "Yes" << endl, 0;
    } while (next_permutation(s.begin(), s.end()));
    sort(s.begin(), s.end());
  } while (next_permutation(t.begin(), t.end()));
  cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
s = input()
t = input()

s.sort()
t.sort(reverse=True)
s = "".join(s)
t = "".join(t)
if s < t:
    print("Yes")
else:
    print("No")


Fixed submission:
s = list(input())
t = list(input())

s.sort()
t.sort(reverse=True)
s = "".join(s)
t = "".join(t)
if s < t:
    print("Yes")
else:
    print("No")
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
import string


S = list(input())
T = list(input())

L = list(string.ascii_lowercase)

S = [L.index(s) for s in S]
T = [L.index(t) for t in T]

S.sort()
T.sort()
T.reverse()

while True:
    if len(S) == 0:
        if len(T) > 0:
            print("Yes")
            break
        else:
            print("No")
            break
    s = S[0]
    t = T[0]
    if s < t:
        print("Yes")
        break
    elif s == t:
        del S[0]
        del T[0]
    else:
        print("No")
        break


Fixed submission:
import string


S = list(input())
T = list(input())

L = list(string.ascii_lowercase)

S = [L.index(s) for s in S]
T = [L.index(t) for t in T]

S.sort()
T.sort()
T.reverse()

while True:
    if len(S) == 0:
        if len(T) > 0:
            print("Yes")
            break
        else:
            print("No")
            break
    if len(T) == 0:
        print("No")
        break
    s = S[0]
    t = T[0]
    if s < t:
        print("Yes")
        break
    elif s == t:
        del S[0]
        del T[0]
    else:
        print("No")
        break
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
s = [*input()]
t = [*input()]
s.sort()
t.sort()
t.reverse()
print("Yes" if s < t else "No")


Fixed submission:
S = input()
T = input()
s = list(S)
t = list(T)
s.sort()
t.sort()
t.reverse()
print("Yes" if s < t else "No")
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)

s, t = readline().decode("utf8").split()
s.sort()
t.sort()
print("Yes" if s < t[::-1] else "No")


Fixed submission:
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)

s, t = read().decode("utf8").split()
S = "".join(sorted(s))
T = "".join(sorted(t))

print("Yes" if S < T[::-1] else "No")
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
s = list(input())
t = list(input())
s.sort()
t.sort()

r = len(s) if len(s) < len(t) else len(t)
for i in range(0, r):
    if not s or not t:
        break
    if s.pop(i) == t.pop(i):
        continue
    elif s.pop(i) < t.pop(i):
        print("Yes")
        exit()
    else:
        print("No")
        exit()
print("Yes") if len(s) < len(t) else print("No")


Fixed submission:
s = list(input())
t = list(input())
s.sort()
t.sort()
t.reverse()
print("Yes") if s < t else print("No")
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
a = input()
b = input()
a = list(a)
b = list(b)

if a.sort(reverse=True) < b.sort():
    print("Yes")
else:
    print("No")


Fixed submission:
a = list(input())
b = list(input())
a.sort()
b.sort()
b.reverse()
a = "".join(a)
b = "".join(b)
if a < b:
    print("Yes")
else:
    print("No")
Problem p03486 (Python)

Buggy submission (status: Runtime Error):
s = sorted(input())
t = sorted(input()).reverse()
print("Yes" if s < t else "No")


Fixed submission:
s = sorted(input())
t = sorted(input())[::-1]
print("Yes" if s < t else "No")
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < static_cast<int>(s.size()); i++) {
    for (int j = static_cast<int>(s.size()) - 1; j > i; j--) {
      if (s.at(j) < s.at(j - 1)) {
        char tmp = s.at(j - 1);
        s.at(j - 1) = s.at(j);
        s.at(j) = tmp;
      }
    }
  }

  for (int i = 0; i < static_cast<int>(s.size()); i++) {
    for (int j = static_cast<int>(s.size()) - 1; j > i; j--) {
      if (t.at(j) > t.at(j - 1)) {
        char tmp = t.at(j - 1);
        t.at(j - 1) = t.at(j);
        t.at(j) = tmp;
      }
    }
  }

  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < static_cast<int>(s.size()); i++) {
    for (int j = static_cast<int>(s.size()) - 1; j > i; j--) {
      if (s.at(j) < s.at(j - 1)) {
        char tmp = s.at(j - 1);
        s.at(j - 1) = s.at(j);
        s.at(j) = tmp;
      }
    }
  }

  for (int i = 0; i < static_cast<int>(t.size()); i++) {
    for (int j = static_cast<int>(t.size()) - 1; j > i; j--) {
      if (t.at(j) > t.at(j - 1)) {
        char tmp = t.at(j - 1);
        t.at(j - 1) = t.at(j);
        t.at(j) = tmp;
      }
    }
  }

  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  vector<char> ss(n);
  vector<char> tt(m);
  rep(i, n) { ss.at(i) = s.at(i); }
  sort(ss.begin(), ss.end());
  rep(i, m) { tt.at(i) = t.at(i); }
  sort(tt.begin(), tt.end());
  reverse(tt.begin(), tt.end());
  bool a = false;
  if (n < m) {
    rep(i, n) {
      int S = ss.at(i);
      int T = tt.at(i);
      if (S < T) {
        a = true;
        break;
      } else if (S == T) {
        if (i == n - 1)
          a = true;
      } else if (S > T)
        break;
    }
  }
  if (n == m) {
    rep(i, n) {
      int S = ss.at(i);
      int T = tt.at(i);
      if (S < T) {
        a = true;
        break;
      } else if (S > T)
        break;
    }
  } else {
    rep(i, m) {
      int S = ss.at(i);
      int T = tt.at(i);
      if (S < T) {
        a = true;
        break;
      } else if (S > T) {
        break;
      }
    }
  }
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm = 1000000000;
ll MM = mm + 7;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  vector<char> ss(n);
  vector<char> tt(m);
  rep(i, n) { ss.at(i) = s.at(i); }
  sort(ss.begin(), ss.end());
  rep(i, m) { tt.at(i) = t.at(i); }
  sort(tt.begin(), tt.end());
  reverse(tt.begin(), tt.end());
  bool a = false;
  if (n < m) {
    rep(i, n) {
      int S = ss.at(i);
      int T = tt.at(i);
      if (S < T) {
        a = true;
        break;
      } else if (S == T) {
        if (i == n - 1)
          a = true;
      } else if (S > T)
        break;
    }
  } else if (n == m) {
    rep(i, n) {
      int S = ss.at(i);
      int T = tt.at(i);
      if (S < T) {
        a = true;
        break;
      } else if (S > T)
        break;
    }
  } else {
    rep(i, m) {
      int S = ss.at(i);
      int T = tt.at(i);
      if (S < T) {
        a = true;
        break;
      } else if (S > T) {
        break;
      }
    }
  }
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s, t;
  string ans = "No";
  cin >> s >> t;
  vector<string> sv(s.length());
  vector<string> tv(t.length());
  for (int i = 0; i < s.length(); i++) {
    sv[i] = s.substr(i, 1);
  }
  for (int i = 0; i < t.length(); i++) {
    tv[i] = t.substr(i, 1);
  }
  sort(sv.begin(), sv.end());
  sort(tv.begin(), tv.end());
  reverse(tv.begin(), tv.end());
  string ns = "";
  string nt = "";
  for (int i = 0; i < t.length(); i++) {
    ns += sv[i];
  }
  for (int i = 0; i < t.length(); i++) {
    nt += tv[i];
  }
  if (ns < nt) {
    ans = "Yes";
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s, t;
  string ans = "No";
  cin >> s >> t;
  vector<string> sv(s.length());
  vector<string> tv(t.length());
  for (int i = 0; i < s.length(); i++) {
    sv[i] = s.substr(i, 1);
  }
  for (int i = 0; i < t.length(); i++) {
    tv[i] = t.substr(i, 1);
  }
  sort(sv.begin(), sv.end());
  sort(tv.begin(), tv.end());
  reverse(tv.begin(), tv.end());
  string ns = "";
  string nt = "";
  for (int i = 0; i < s.length(); i++) {
    ns += sv[i];
  }
  for (int i = 0; i < t.length(); i++) {
    nt += tv[i];
  }
  if (ns < nt) {
    ans = "Yes";
  }
  cout << ans << endl;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  vector<char> s1;
  vector<char> t1;
  for (int i = 0; i < s.size(); i++) {
    s1.at(i) = s.at(i);
  }
  for (int i = 0; i < t.size(); i++) {
    t1.at(i) = t.at(i);
  }
  sort(s1.begin(), s1.end());
  sort(t1.begin(), t1.end());
  reverse(t1.begin(), t1.end());
  for (int i = 0; i < s.size(); i++) {
    s.at(i) = s1.at(i);
  }
  for (int i = 0; i < t.size(); i++) {
    t.at(i) = t1.at(i);
  }
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int N = s.size();
  int M = t.size();
  vector<char> S(N);
  vector<char> T(N);
  for (int i = 0; i < N; i++)
    S[i] = s.at(i);
  for (int j = 0; j < M; j++)
    T[j] = t.at(j);
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  int Min = min(N, M);
  string ans = "dontknow";
  for (int i = 0; i < Min; i++) {
    if (S.at(i) < T.at(i)) {
      ans = "Yes";
      break;
    }

    if (S.at(i) > T.at(i)) {
      ans = "No";
      break;
    }
  }
  if (ans == "dontknow") {
    if (Min < M)
      ans = "Yes";
    else
      ans = "No";
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int N = s.size();
  int M = t.size();
  vector<char> S(N);
  vector<char> T(M);
  for (int i = 0; i < N; i++)
    S[i] = s.at(i);
  for (int j = 0; j < M; j++)
    T[j] = t.at(j);
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  int Min = min(N, M);
  string ans = "dontknow";
  for (int i = 0; i < Min; i++) {
    if (S.at(i) < T.at(i)) {
      ans = "Yes";
      break;
    }

    if (S.at(i) > T.at(i)) {
      ans = "No";
      break;
    }
  }
  if (ans == "dontknow") {
    if (Min < M)
      ans = "Yes";
    else
      ans = "No";
  }
  cout << ans << endl;

  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s, t, ans;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  // cout << s << ", " << t << endl;
  for (int i = 0; i < s.size(); ++i) {
    if (s.at(i) > t.at(i)) {
      ans = "No";
      break;
    } else if (s.at(i) < t.at(i)) {
      ans = "Yes";
      break;
    } else if (i == s.size() - 1 && s.size() < t.size())
      ans = "Yes";
    else if (i == s.size() - 1 && s.size() >= t.size())
      ans = "No";
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s, t, ans;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s >= t)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), s.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.end(), t.begin());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.rbegin(), S.rend());
  if (S < T) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.rbegin(), T.rend());
  if (S < T) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;

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

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

  int p = 0;
  for (int i = 0; i < a.size(); i++) {
    int num = count(a.begin(), a.end(), a[i]);
    if (num < a[i]) {
      p += num;
    } else if (num > a[i]) {
      p += num - a[i];
    }

    i += num - 1;
  }

  cout << p << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;

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

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

  int p = 0;
  for (int i = 0; i < a.size(); i++) {
    int num = 1;
    int j = 1;
    while (a[i] == a[i + j]) {
      num++;
      j++;
    }

    if (num < a[i]) {
      p += num;
    } else if (num > a[i]) {
      p += num - a[i];
    }

    i += num - 1;
  }

  cout << p << endl;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
int N, ans;
int mp[maxn];

int main() {
  cin >> N;
  ans = 0;
  memset(mp, 0, sizeof(mp));
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    if (tmp > N)
      ans++;
    else {
      mp[tmp]++;
    }
  }
  for (int i = 0; i <= N; i++) {
    if (mp[i] != 0) {
      if (mp[i] != i) {
        if (mp[i] < i)
          ans += mp[i];
        else
          ans += mp[i] - i;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int N, ans;
int mp[maxn];

int main() {
  cin >> N;
  ans = 0;
  memset(mp, 0, sizeof(mp));
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    if (tmp > N)
      ans++;
    else {
      mp[tmp]++;
    }
  }
  for (int i = 0; i <= N; i++) {
    if (mp[i] != 0) {
      if (mp[i] != i) {
        if (mp[i] < i)
          ans += mp[i];
        else
          ans += mp[i] - i;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[10000];
int main() {
  int n, i, j, x, s = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    x = 0;
    j = i;
    while (a[i] == a[j]) {
      x++;
      j++;
    }
    if (a[i] < x) {
      s += x - a[i];
    } else if (a[i] > x) {
      s += x;
    }
    i = j - 1;
  }
  cout << s;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
  int n, i, j, x, s = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    x = 0;
    j = i;
    while (a[i] == a[j]) {
      x++;
      j++;
    }
    if (a[i] < x) {
      s += x - a[i];
    } else if (a[i] > x) {
      s += x;
    }
    i = j - 1;
  }
  cout << s;
  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, a;
  cin >> N;
  vector<long long> b(1000000001);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    b[a]++;
    ans++;
    if (b[a] == a)
      ans -= a;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, a;
  cin >> N;
  map<long long, int> b;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    b[a]++;
    ans++;
    if (b[a] == a)
      ans -= a;
  }
  cout << ans << endl;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
using namespace std;
const int maxn = 10005;
map<int, int> Q;
int sum, ans, n, x;
int a[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;

    if (!Q.count(x)) {
      a[ans++] = x;
    }
    Q[x]++;
    if (Q[x] > x) {
      Q[x]--;
      sum++;
    }
  }
  for (int i = 0; i < ans; i++) {
    if (a[i] != Q[a[i]])
      sum += Q[a[i]];
  }
  cout << sum << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
using namespace std;
const int maxn = 100005;
map<int, int> Q;
int sum, ans, n, x;
int a[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;

    if (!Q.count(x)) {
      a[ans++] = x;
    }
    Q[x]++;
    if (Q[x] > x) {
      Q[x]--;
      sum++;
    }
  }
  for (int i = 0; i < ans; i++) {
    if (a[i] != Q[a[i]])
      sum += Q[a[i]];
  }
  cout << sum << endl;
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int m, a[100000], ans, in;
int main() {
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> in;
    if (in > m)
      ans++;
    else
      a[in]++;
  }
  for (int j = 1; j <= m; j++) {
    if (a[j] > j)
      ans = ans + a[j] - j;
    if (a[j] < j)
      ans = ans + a[j];
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int m, a[100005], ans, in;
int main() {
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> in;
    if (in > m)
      ans++;
    else
      a[in]++;
  }
  for (int j = 1; j <= m; j++) {
    if (a[j] > j)
      ans = ans + a[j] - j;
    if (a[j] < j)
      ans = ans + a[j];
  }
  cout << ans;
  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

int n = 0;
int a[10020] = {0};
priority_queue<int> seq;
vector<pii> seq2;

int solve() {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    seq.push(a[i]);
  }
  while (seq.size()) {
    int cmp = seq.top();
    int mem = 1;
    seq.pop();
    while (seq.size()) {
      int cmp2 = seq.top();
      if (cmp != cmp2)
        break;
      seq.pop();
      mem++;
    }
    seq2.push_back(pii(cmp, mem));
  }
  for (int i = 0; i < seq2.size(); i++) {
    pii cmp = seq2[i];
    if (cmp.first < cmp.second)
      ans += (cmp.second - cmp.first);
    if (cmp.first > cmp.second)
      ans += cmp.second;
  }
  return ans;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  printf("%d\n", solve());
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

int n = 0;
int a[100020] = {0};
priority_queue<int> seq;
vector<pii> seq2;

int solve() {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    seq.push(a[i]);
  }
  while (seq.size()) {
    int cmp = seq.top();
    int mem = 1;
    seq.pop();
    while (seq.size()) {
      int cmp2 = seq.top();
      if (cmp != cmp2)
        break;
      seq.pop();
      mem++;
    }
    seq2.push_back(pii(cmp, mem));
  }
  for (int i = 0; i < seq2.size(); i++) {
    pii cmp = seq2[i];
    if (cmp.first < cmp.second)
      ans += (cmp.second - cmp.first);
    if (cmp.first > cmp.second)
      ans += cmp.second;
  }
  return ans;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  printf("%d\n", solve());
  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int a[100001] = {}, N, temp, ans = 0;

int main() {
  cin >> N;
  rep(i, N) {
    cin >> temp;
    a[temp]++;
  }
  repi(i, 1, 100001) {
    if (a[i] != i) {
      if (a[i] > i) {
        ans += a[i] - i;
      } else {
        ans += a[i];
      }
    }
  }
  out(ans);
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int a[100001] = {}, N, temp, ans = 0;

int main() {
  cin >> N;
  rep(i, N) {
    cin >> temp;
    if (temp > 100000)
      ans++;
    else
      a[temp]++;
  }
  repi(i, 1, 100001) {
    if (a[i] != i) {
      if (a[i] > i) {
        ans += a[i] - i;
      } else {
        ans += a[i];
      }
    }
  }
  out(ans);
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  int B[10001] = {0};
  int del = 0;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a > N) {
      del++;
      continue;
    }
    B[a]++;
  }

  for (int i = 1; i <= N; i++) {
    if (B[i] == 0)
      continue;

    if (i > B[i]) {
      del += B[i];
    } else {
      del += (B[i] - i);
    }
  }

  cout << del << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  int B[100001] = {0};
  int del = 0;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a > N) {
      del++;
      continue;
    }
    B[a]++;
  }

  for (int i = 1; i <= N; i++) {
    if (B[i] == 0)
      continue;

    if (i > B[i]) {
      del += B[i];
    } else {
      del += (B[i] - i);
    }
  }

  cout << del << endl;

  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  int n, x = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  int b[100005];
  for (int i = 1; i <= min(n, a[n - 1]); i++)
    b[i] = 0;
  for (int i = 0; i < n; i++) {
    b[a[i]]++;
  }
  for (int i = 1; i <= min(n, a[n - 1]); i++) {
    if (b[i] > 0) {
      if (i != b[i]) {
        if (b[i] > i)
          x += b[i] - i;
        else
          x += b[i];
      }
    }
  }
  cout << x;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  int n, x = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  int b[100005];
  for (int i = 1; i <= min(n, a[n - 1]); i++)
    b[i] = 0;
  for (int i = 0; i < n; i++)
    if (a[i] > n)
      x++;
  for (int i = 0; i < n; i++)
    if (a[i] <= n) {
      b[a[i]]++;
    }
  for (int i = 1; i <= min(n, a[n - 1]); i++) {
    if (b[i] > 0) {
      if (i != b[i]) {
        if (b[i] > i)
          x += b[i] - i;
        else
          x += b[i];
      }
    }
  }
  cout << x;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> vec(n), ans(n);
  rep(i, n) { cin >> vec.at(i); }
  int64_t answer = 0;
  for (int64_t x : vec) {
    if (x > 100000) {
      answer++;
      continue;
    }
    ans.at(x - 1)++;
  }
  rep(i, n) {
    if (ans.at(i) >= i + 1) {
      answer += ans.at(i) - i - 1;
    } else {
      answer += ans.at(i);
    }
  }
  cout << answer;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> vec(n), ans(n);
  rep(i, n) { cin >> vec.at(i); }
  int64_t answer = 0;
  for (int64_t x : vec) {
    if (x > n) {
      answer++;
      continue;
    }
    ans.at(x - 1)++;
  }
  rep(i, n) {
    if (ans.at(i) >= i + 1) {
      answer += ans.at(i) - i - 1;
    } else {
      answer += ans.at(i);
    }
  }
  cout << answer;
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N;
  int a[100000];
  int ans = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  sort(a, a + N);
  for (int i = 0; i < N;) {
    int tmp = a[i];
    int cnt = count(a + i, a + N, tmp);
    if (tmp > cnt) {
      ans += cnt;
    } else if (tmp < cnt) {
      ans += (cnt - tmp);
    }
    i += cnt;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int N;
  int a[100000];
  int ans = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  sort(a, a + N);
  for (int i = 0; i < N;) {
    int tmp = a[i];
    int cnt = 0;
    for (int k = 0;; k++) {
      if (a[i + k] == tmp) {
        cnt++;
      } else {
        break;
      }
    }
    if (tmp > cnt) {
      ans += cnt;
    } else if (tmp < cnt) {
      ans += (cnt - tmp);
    }
    i += cnt;
  }
  cout << ans << endl;
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "stdio.h"

int num;
int a[100000];
int log[100000];

int main(void) {
  int N;
  int i, j;
  int cnt = 0;

  scanf("%d", &N);

  for (i = 0; i < N; i++) {
    scanf("%d", &num);
    for (j = 0; j < N; j++) {
      if (a[j] == 0 || a[j] == num) {
        log[j]++;
        a[j] = num;
        break;
      }
    }
  }

  for (j = 0; j < N; j++) {
    if (log[j] >= a[j]) {
      cnt += log[j] - a[j];
    } else {
      cnt += log[j];
    }
  }

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

Fixed submission:
#include "stdio.h"

int num;
int a[100000];
int log[100000];

int main(void) {
  int N;
  int i, j;
  int cnt = 0;

  scanf("%d", &N);

  for (i = 0; i < N; i++) {
    scanf("%d", &num);
    if (num > 100000) {
      cnt++;
      continue;
    };

    for (j = 0; j < N; j++) {
      if (a[j] == 0 || a[j] == num) {
        log[j]++;
        a[j] = num;
        break;
      }
    }
  }

  for (j = 0; j < N; j++) {
    if (log[j] >= a[j]) {
      cnt += log[j] - a[j];
    } else {
      cnt += log[j];
    }
  }

  printf("%d\n", cnt);
  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iterator>
#include <math.h>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define MOD 1000000007
using namespace std;

int main(int argc, char *argv[]) {
  long n;
  scanf("%ld", &n);

  vector<long> a(n);
  long i;
  for (i = 0; i < n; i++) {
    scanf("%ld", &(a[i]));
  }
  sort(a.begin(), a.end());

  long ans = 0;
  for (i = 0; i < n; i++) {
    long curr = a[i];
    long k = i;
    long count = 0;
    while (k < n) {
      if (a[k] == curr)
        count++;
      k++;
    }
    if (count >= curr) {
      ans += curr;
    }
    i += (count - 1);
  }
  printf("%ld\n", n - ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <iterator>
#include <math.h>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define MOD 1000000007
using namespace std;

int main(int argc, char *argv[]) {
  long n;
  scanf("%ld", &n);

  vector<long> a(n);
  long i;
  for (i = 0; i < n; i++) {
    scanf("%ld", &(a[i]));
  }
  sort(a.begin(), a.end());

  long ans = 0;
  for (i = 0; i < n; i++) {
    long curr = a[i];
    long k = i;
    long count = 0;
    while (k < n && a[k] == curr) {
      count++;
      k++;
    }
    if (count >= curr) {
      ans += curr;
    }
    i += (count - 1);
  }
  printf("%ld\n", n - ans);

  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int a[114514];
  for (int i = 0; i < N; ++i) {
    int n;
    cin >> n;
    a[n]++;
  }
  int S = N;
  for (int i = 1; i <= N; ++i) {
    if (a[i] < i)
      S -= 0;
    else
      S -= i;
  }
  cout << S << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int a[114514];
  for (int i = 0; i < N; ++i) {
    int n;
    cin >> n;
    if (n < 114514)
      a[n]++;
  }
  int S = N;
  for (int i = 1; i <= N; ++i) {
    if (a[i] < i)
      S -= 0;
    else
      S -= i;
  }
  cout << S << endl;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int n, a[10000], num[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] <= n)
      num[a[i]]++;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > n)
      continue;
    if (num[a[i]] >= a[i]) {
      cnt += a[i];
      num[a[i]] = 0;
    }
  }
  cout << n - cnt << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int n, a[100000], num[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] <= n)
      num[a[i]]++;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > n)
      continue;
    if (num[a[i]] >= a[i]) {
      cnt += a[i];
      num[a[i]] = 0;
    }
  }
  cout << n - cnt << endl;
  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

map<ll, ll> mp;

int main() {
  cin >> n;
  vi v(n);
  REP(i, n) {
    cin >> v[i];
    mp[v[i]]++;
    k = max(k, v[i]);
  }
  FOR(i, 1, k + 1) {
    if (mp[i] != 0) {
      if (mp[i] < i) {
        cnt += mp[i];
      } else {
        cnt += abs(mp[i] - i);
      }
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

map<ll, ll> mp;

int main() {
  cin >> n;
  vi v(n);
  REP(i, n) {
    cin >> v[i];
    if (v[i] > 100005) {
      cnt++;
    } else {
      mp[v[i]]++;
      k = max(k, v[i]);
    }
  }
  FOR(i, 1, k + 1) {
    if (mp[i] != 0) {
      if (mp[i] < i) {
        cnt += mp[i];
      } else {
        cnt += abs(mp[i] - i);
      }
    }
  }
  cout << cnt << endl;
}
Problem p03487 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
const int N = 100005;
using namespace std;
ll n, a[N], b[N], ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], b[a[i]]++;
  for (int i = 1; i <= n; i++) {
    if (b[a[i]] > a[i])
      ans += b[a[i]] - a[i], b[a[i]] = a[i];
    else if (b[a[i]] < a[i])
      ans += b[a[i]], b[a[i]] = 0;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
const int N = 100005;
using namespace std;
map<ll, ll> b;
ll n, a[N], ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], b[a[i]]++;
  for (int i = 1; i <= n; i++) {
    if (b[a[i]] > a[i])
      ans += b[a[i]] - a[i], b[a[i]] = a[i];
    else if (b[a[i]] < a[i])
      ans += b[a[i]], b[a[i]] = 0;
  }
  cout << ans;
  return 0;
}
Problem p03487 (Python)

Buggy submission (status: Time Limit Exceeded):
# Good Sequence
n = int(input())
a = list(map(int, input().split()))
a_ = set(a)
p = 0
for i in a_:
    if a.count(i) < i:
        p += a.count(i)
    elif a.count(i) > i:
        p += a.count(i) - i
print(p)


Fixed submission:
# Good Sequence
n = int(input())
a = list(map(int, 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)
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

const int kMaxN = 100000;

int n;
int a[kMaxN];
int ans = 0;

int main() {
  cin >> n;
  REP(i, n) { cin >> a[i]; }

  sort(a, a + n);
  int i = 0;
  while (i < n) {
    int ai = a[i];
    int ai_cnt = 0;
    for (int j = 0; a[i + j] != ai || i + j == n; ++j) {
      ++ai_cnt;
    }
    if (ai_cnt < ai) {
      ans += ai_cnt;
    } else if (ai_cnt == ai) {
      ;
    } else {
      ans += ai_cnt - ai;
    }
    i += ai_cnt;
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

const int kMaxN = 100000;

int n;
int a[kMaxN];
int ans = 0;

int main() {
  cin >> n;
  REP(i, n) { cin >> a[i]; }

  sort(a, a + n);
  int i = 0;
  while (i < n) {
    int ai = a[i];
    int ai_cnt = 0;
    for (int j = 0; a[i + j] == ai && i + j < n; ++j) {
      ++ai_cnt;
    }
    if (ai_cnt < ai) {
      ans += ai_cnt;
    } else if (ai_cnt == ai) {
      ;
    } else {
      ans += ai_cnt - ai;
    }
    i += ai_cnt;
  }

  cout << ans << endl;
  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

int main() {
  int *nums;
  int numsCount;

  std::cin >> numsCount;
  nums = new int[numsCount];
  for (int i = 0; i < numsCount; i++) {
    std::cin >> nums[i];
  }

  std::vector<int> appearedNums = {};
  std::vector<int> appearedCounts = {};
  int eliminateCount = 0;

  for (int i = 0; i < numsCount; i++) {
    bool newbie = true;
    for (int j = 0; j < appearedNums.size(); j++) {
      if (nums[i] == appearedNums[j]) {
        newbie = false;
        appearedCounts[j]++;
        break;
      }
    }
    if (newbie) {
      appearedNums.push_back(nums[i]);
      appearedCounts.push_back(1);
    }
  }

  for (int i = 0; i < appearedNums.size(); i++) {
    if (appearedCounts[i] >= appearedNums[i])
      eliminateCount += appearedCounts[i] - appearedNums[i];
    else
      eliminateCount += appearedCounts[i];
  }

  std::cout << eliminateCount;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

int main() {
  int *nums;
  int numsCount;

  std::cin >> numsCount;
  nums = new int[numsCount];
  for (int i = 0; i < numsCount; i++) {
    std::cin >> nums[i];
  }

  std::vector<int> appearedNums = {};
  std::vector<int> appearedCounts = {};
  int eliminateCount = 0;

  for (int i = 0; i < numsCount; i++) {
    bool newbie = true;
    for (int j = 0; j < appearedNums.size(); j++) {
      if (nums[i] == appearedNums[j]) {
        newbie = false;
        appearedCounts[j]++;
        break;
      }
    }
    if (newbie) {
      if (nums[i] > numsCount - i) {
        eliminateCount += 1;
      } else {
        appearedNums.push_back(nums[i]);
        appearedCounts.push_back(1);
      }
    }
  }

  for (int i = 0; i < appearedNums.size(); i++) {
    if (appearedCounts[i] >= appearedNums[i])
      eliminateCount += appearedCounts[i] - appearedNums[i];
    else
      eliminateCount += appearedCounts[i];
  }

  std::cout << eliminateCount;

  return 0;
}
Problem p03487 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());

  int ans = 0;
  int i = 0;
  while (i < N) {
    int x = vec.at(i);
    int cnt = 1;
    while (cnt + i < N) {
      if (x == vec.at(i + cnt)) {
        cnt++;
      } else {
        i += cnt;
        break;
      }
      if (i + cnt == N) {
        i += cnt;
        break;
      }
    }
    if (cnt > x) {
      ans += cnt - x;
    } else if (cnt < x) {
      ans += cnt;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());

  int ans = 0;
  int i = 0;
  while (i < N) {
    int x = vec.at(i);
    int cnt = 1;
    if (cnt + i == N) {
      i++;
    }
    while (cnt + i < N) {
      if (x == vec.at(i + cnt)) {
        cnt++;
      } else {
        i += cnt;
        break;
      }
      if (i + cnt == N) {
        i += cnt;
        break;
      }
    }
    if (cnt > x) {
      ans += cnt - x;
    } else if (cnt < x) {
      ans += cnt;
    }
  }
  cout << ans << endl;
}