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

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

int main() {
  int n, m;
  cin >> n;
  vector<string> s(n);
  vector<int> c(n, 1);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < n; i++) {
    cin >> t.at(i);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n && j != i; j++) {
      if (s.at(i) == s.at(j)) {
        c.at(i)++;
      }
    }
    for (int k = 0; k < m; k++) {
      if (s.at(i) == t.at(k)) {
        c.at(i)--;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < n; i++) {
    if (max < c.at(i)) {
      max = c.at(i);
    }
  }
  if (max > 0) {
    cout << max;
  } else {
    cout << 0;
  }
}

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

int main() {
  int n, m;
  cin >> n;
  vector<string> s(n);
  vector<int> c(n, 1);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++) {
    cin >> t.at(i);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n && j != i; j++) {
      if (s.at(i) == s.at(j)) {
        c.at(i)++;
      }
    }
    for (int k = 0; k < m; k++) {
      if (s.at(i) == t.at(k)) {
        c.at(i)--;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < n; i++) {
    if (max < c.at(i)) {
      max = c.at(i);
    }
  }
  if (max > 0) {
    cout << max;
  } else {
    cout << 0;
  }
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, j, i;
  cin >> a;
  c = 0;
  vector<string> blue(100);
  for (i = 0; i < a; i++) {
    cin >> blue.at(i);
  }
  cin >> b;
  vector<string> red(100);
  for (i = 0; i < b; i++) {
    cin >> red.at(i);
  }
  for (i = 0; i < a; i++) {
    d = 0;
    for (j = 0; j < 100; j++) {
      if (blue.at(i) == blue.at(j + 1)) {
        d++;
      }
      if (blue.at(i) == red.at(j)) {
        d--;
      }
    }
    if (d > c) {
      c = d;
    }
  }
  cout << c << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, j, i;
  cin >> a;
  c = 0;
  vector<string> blue(100);
  for (i = 0; i < a; i++) {
    cin >> blue.at(i);
  }
  cin >> b;
  vector<string> red(100);
  for (i = 0; i < b; i++) {
    cin >> red.at(i);
  }
  for (i = 0; i < a; i++) {
    d = 0;
    for (j = 0; j < 100; j++) {
      if (blue.at(i) == blue.at(j)) {
        d++;
      }
      if (blue.at(i) == red.at(j)) {
        d--;
      }
    }
    if (d > c) {
      c = d;
    }
  }
  cout << c << endl;
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
char s[15];
int mod = 19260817, base = 31, vis[500], Num;
int n, m, num[10000000];
int hashe(char t[]) {
  int len = strlen(t);
  int ans = 0;
  for (int i = 0; i < len; i++)
    ans = (ans * 3) + t[i] * 31 % mod;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    int now = hashe(s);
    vis[++Num] = now;
    num[now]++;
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    cin >> s;
    num[hashe(s)]--;
  }
  int Max = 0;
  for (int i = 1; i <= Num; i++) {
    Max = max(Max, num[vis[i]]);
  }
  cout << Max;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
char s[15];
int mod = 19260817, base = 31, vis[500], Num;
int n, m, num[10000000];
int hashe(char t[]) {
  int len = strlen(t);
  int ans = 0;
  for (int i = 0; i < len; i++)
    ans += t[i] * 31 % mod + ans / 17;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s;
    int now = hashe(s);
    vis[++Num] = now;
    num[now]++;
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    cin >> s;
    num[hashe(s)]--;
  }
  int Max = 0;
  for (int i = 1; i <= Num; i++) {
    Max = max(Max, num[vis[i]]);
  }
  cout << Max;
  return 0;
}
Problem p03408 (C++)

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

void aaa(int *a, int start, int end) {
  if (start < end) {
    for (int i = start; i < end; i++) {
      if (a[i] > a[i + 1]) {
        int tmp = a[i];
        a[i] = a[i + 1];
        a[i + 1] = tmp;
      }
    }
    aaa(a, start, end - 1);
  }
}

int main(void) {
  using namespace std;

  int n, m, count[100];
  string s[100], t[100];

  cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> s[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> t[i];
  }
  s[n] = "";

  for (int i = 0; i < n + 1; i++) {
    count[i] = 0;
    for (int j = 0; j < n; j++) {
      if (s[i] == s[j])
        count[i]++;
    }
    for (int k = 0; k < m; k++) {
      if (s[i] == t[k])
        count[i]--;
    }
  }

  aaa(count, 0, n);
  std::cout << count[n] << endl;
}


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

void aaa(int *a, int start, int end) {
  if (start < end) {
    for (int i = start; i < end; i++) {
      if (a[i] > a[i + 1]) {
        int tmp = a[i];
        a[i] = a[i + 1];
        a[i + 1] = tmp;
      }
    }
    aaa(a, start, end - 1);
  }
}

int main(void) {
  using namespace std;

  int n, m, count[101];
  string s[101], t[101];

  cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> s[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> t[i];
  }
  s[n] = "";

  for (int i = 0; i < n + 1; i++) {
    count[i] = 0;
    for (int j = 0; j < n; j++) {
      if (s[i] == s[j])
        count[i]++;
    }
    for (int k = 0; k < m; k++) {
      if (s[i] == t[k])
        count[i]--;
    }
  }

  aaa(count, 0, n);
  std::cout << count[n] << endl;
}
Problem p03408 (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() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s[i];
  cin >> M;
  vector<string> t(M);
  rep(i, M) cin >> t[i];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int score = 0;
    for (int j = 0; j < N; j++) {
      if (s[i] == s[j]) {
        score++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (t[j] == t[i]) {
        score--;
      }
    }
    ans = max(ans, score);
  }
  cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s[i];
  cin >> M;
  vector<string> t(M);
  rep(i, M) cin >> t[i];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int score = 0;
    for (int j = 0; j < N; j++) {
      if (s[i] == s[j]) {
        score++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (t[j] == s[i]) {
        score--;
      }
    }
    ans = max(ans, score);
  }
  cout << ans << endl;
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (size_t i = 0; i < N; i++) {
    cin >> s[i];
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for (size_t i = 0; i < M; i++) {
    cin >> t[i];
  }
  map<string, int> points;
  for (int i = 0; i < N; ++i)
    points[s[i]]++;
  for (int i = 0; i < N; ++i)
    points[t[i]]--;
  int ret = 0;
  for (auto point : points) {
    if (point.second > ret)
      ret = point.second;
  }
  cout << ret << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (size_t i = 0; i < N; i++) {
    cin >> s[i];
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for (size_t i = 0; i < M; i++) {
    cin >> t[i];
  }
  map<string, int> points;
  for (int i = 0; i < N; ++i)
    points[s[i]]++;
  for (int i = 0; i < M; ++i)
    points[t[i]]--;
  int ret = 0;
  for (auto point : points) {
    if (point.second > ret)
      ret = point.second;
  }
  cout << ret << endl;
  return 0;
}
Problem p03408 (C++)

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

int main() {
  int m, n;
  int value = 0;
  cin >> m;
  vector<string> blue(m);
  for (int i = 0; i < m; i++) {
    cin >> blue.at(i);
  }

  cin >> n;
  vector<string> red(n);
  for (int i = 0; i < n; i++) {
    cin >> red.at(i);
  }

  for (int i = 0; i < m; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      if (blue.at(i) == blue.at(j))
        cnt++;
      if (blue.at(i) == red.at(j))
        cnt--;
    }
    value = max(value, cnt);
  }
  cout << value << endl;
}


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

int main() {
  int m, n;
  int value = 0;
  cin >> m;
  vector<string> blue(m);
  for (int i = 0; i < m; i++) {
    cin >> blue.at(i);
  }

  cin >> n;
  vector<string> red(n);
  for (int i = 0; i < n; i++) {
    cin >> red.at(i);
  }

  for (int i = 0; i < m; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      if (blue.at(i) == blue.at(j))
        cnt++;
    }
    for (int j = 0; j < n; j++) {
      if (blue.at(i) == red.at(j))
        cnt--;
    }
    value = max(value, cnt);
  }
  cout << value << endl;
}
Problem p03408 (C++)

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

int main() {

  uint bule_count;
  cin >> bule_count;
  string input_str;
  // 100要素の配列で初期化
  map<string, int> card;
  // cout << "bule_count:" << bule_card.size() << endl;
  //  100個の入力を受け取る
  for (uint i = 0; bule_count > i; i++) {
    cin >> input_str;
    if (card.count(input_str)) {
      card.at(input_str)++;
    } else {
      card[input_str] = 1;
    }
  }

  uint red_count;
  cin >> red_count;
  for (uint i = 0; red_count > i; i++) {
    cin >> input_str;
    if (card.count(input_str)) {
      card.at(input_str)--;
    } else {
      card[input_str] = -1;
    }
  }

  string max_key;
  int max_val = 0;
  // debug print
  for (auto itr = card.begin(); itr != card.end(); ++itr) {
    // std::cout << "key = " << itr->first << ", val = " << itr->second << "\n";
    if (max_val < itr->second) {
      max_key = itr->first;
      max_val = itr->second;
    }
  }

  cout << card.at(max_key) << endl;
}

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

int main() {

  uint bule_count;
  cin >> bule_count;
  string input_str;
  // 100要素の配列で初期化
  map<string, int> card;
  // cout << "bule_count:" << bule_card.size() << endl;
  //  100個の入力を受け取る
  for (uint i = 0; bule_count > i; i++) {
    cin >> input_str;
    if (card.count(input_str)) {
      card.at(input_str)++;
    } else {
      card[input_str] = 1;
    }
  }

  uint red_count;
  cin >> red_count;
  for (uint i = 0; red_count > i; i++) {
    cin >> input_str;
    if (card.count(input_str)) {
      card.at(input_str)--;
    } else {
      card[input_str] = -1;
    }
  }

  string max_key;
  int max_val = 0;
  // debug print
  for (auto itr = card.begin(); itr != card.end(); ++itr) {
    // std::cout << "key = " << itr->first << ", val = " << itr->second << "\n";
    if (max_val < itr->second) {
      max_key = itr->first;
      max_val = itr->second;
    }
  }

  // cout << card.at(max_key) << endl;
  cout << max_val << endl;
}
Problem p03408 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

struct Fish {
  ll beauty;
  ll taste;
};

ll fact(ll n) {
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return 1;
  }
  return n * fact(n - 1) % MOD;
}

int main() {
  ll a, b;
  cin >> a >> b;

  map<string, ll> BLUE;
  map<string, ll> RED;

  ll N;
  cin >> N;
  for (ll i = 0; i < N; i++) {
    string s;
    cin >> s;
    BLUE[s] += 1;
  }

  ll M;
  cin >> M;
  for (ll i = 0; i < M; i++) {
    string s;
    cin >> s;
    RED[s] += 1;
  }

  ll ans = 0;
  for (auto &&e : BLUE) {
    ans = max(ans, e.second - RED[e.first]);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}

struct Fish {
  ll beauty;
  ll taste;
};

ll fact(ll n) {
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return 1;
  }
  return n * fact(n - 1) % MOD;
}

int main() {
  map<string, ll> BLUE;
  map<string, ll> RED;

  ll N;
  cin >> N;
  for (ll i = 0; i < N; i++) {
    string s;
    cin >> s;
    BLUE[s] += 1;
  }

  ll M;
  cin >> M;
  for (ll i = 0; i < M; i++) {
    string s;
    cin >> s;
    RED[s] += 1;
  }

  ll ans = 0;
  for (auto &&e : BLUE) {
    ans = max(ans, e.second - RED[e.first]);
  }
  cout << ans << endl;
}
Problem p03408 (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<string, int> P;

int main() {
  int N, M;
  vector<P> card;

  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    card.push_back(make_pair(S, 1));
  }

  cin >> M;
  for (int i = 0; i < M; i++) {
    string S;
    cin >> S;
    card.push_back(make_pair(S, -1));
  }

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

  int ans = 0;
  int i = 0;
  while (i < N + M) {
    int candidate = 0;
    while (card[i].first == card[i + 1].first) {
      candidate += card[i].second;
      i++;
    }
    candidate += card[i].second;
    ans = max(ans, candidate);
    i++;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<string, int> P;

int main() {
  int N, M;
  vector<P> card;

  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    card.push_back(make_pair(S, 1));
  }

  cin >> M;
  for (int i = 0; i < M; i++) {
    string S;
    cin >> S;
    card.push_back(make_pair(S, -1));
  }

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

  int ans = 0;
  int i = 0;
  while (i < N + M) {
    int candidate = 0;
    while (i + 1 < N + M && card[i].first == card[i + 1].first) {
      candidate += card[i].second;
      i++;
    }
    candidate += card[i].second;
    ans = max(ans, candidate);
    i++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03409 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int V;
vector<int> G[101];
int match[101];
bool used[101];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    int w = match[u];
    if (w < 0 || (!used[w] && dfs(w))) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int main() {
  int rx[101], ry[101], bx[101], by[101];
  cin >> V;
  for (int i = 0; i < V; i++) {
    cin >> rx[i] >> ry[i];
  }
  for (int i = 0; i < V; i++) {
    cin >> bx[i] >> by[i];
  }
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (rx[i] < bx[j] && ry[i] < by[j]) {
        add_edge(i, V + j);
      }
    }
  }

  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < (2 * V); v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int V;
vector<int> G[201];
int match[201];
bool used[201];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    int w = match[u];
    if (w < 0 || (!used[w] && dfs(w))) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int main() {
  int rx[101], ry[101], bx[101], by[101];
  cin >> V;
  for (int i = 0; i < V; i++) {
    cin >> rx[i] >> ry[i];
  }
  for (int i = 0; i < V; i++) {
    cin >> bx[i] >> by[i];
  }
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (rx[i] < bx[j] && ry[i] < by[j]) {
        add_edge(i, V + j);
      }
    }
  }

  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < (2 * V); v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03409 (C++)

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

using namespace std;

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  vector<P> a_l(N), b_l(N);
  for (int i = 0; i < N; i++) {
    cin >> a_l[i].second >> a_l[i].first;
  }
  for (int i = 0; i < N; i++) {
    cin >> b_l[i].first >> b_l[i].second;
  }
  sort(b_l.begin(), b_l.end(), [](P x, P y) {
    if (x.first < y.first)
      return x < y;
    else
      return x.second < y.second;
  });
  sort(a_l.begin(), a_l.end(), [](P x, P y) {
    if (x.first > y.first)
      return x > y;
    else
      return x.second > y.second;
  });
  vector<bool> check(N, false);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (a_l[j].second < b_l[i].first && a_l[j].first < b_l[i].second &&
          !check[j]) {
        check[j] = true;
        cnt++;
        break;
      }
    }
  }
  cout << cnt << "\n";
}

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

using namespace std;

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  vector<P> a_l(N), b_l(N);
  for (int i = 0; i < N; i++) {
    cin >> a_l[i].second >> a_l[i].first;
  }
  for (int i = 0; i < N; i++) {
    cin >> b_l[i].first >> b_l[i].second;
  }
  sort(b_l.begin(), b_l.end());
  sort(a_l.begin(), a_l.end(), greater<P>());
  vector<bool> check(N, false);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (a_l[j].second < b_l[i].first && a_l[j].first < b_l[i].second &&
          !check[j]) {
        check[j] = true;
        cnt++;
        break;
      }
    }
  }
  cout << cnt << "\n";
}
Problem p03409 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int ao[203][203];

int main() {
  int n, a, b, ans = 0;
  cin >> n;
  rep(i, n) cin >> a >> b, ao[b][a] = 1;

  vector<pair<int, int>> p(n);
  rep(i, n) cin >> p[i].second >> p[i].first;
  sort(p.begin(), p.end());

  rep(i, n) {
    int x = -1, y = -1;
    rep(j, p[i].second) {
      rep(k, p[i].first) {
        if (ao[k][j])
          x = j, y = k;
      }
    }
    if (a != -1)
      ao[y][x] = 0, ans++;
  }

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


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int ao[203][203];

int main() {
  int n, a, b, ans = 0;
  cin >> n;
  rep(i, n) cin >> a >> b, ao[b][a] = 1;

  vector<pair<int, int>> p(n);
  rep(i, n) cin >> p[i].second >> p[i].first;
  sort(p.begin(), p.end());

  rep(i, n) {
    int x = -1, y = -1;
    rep(j, p[i].second) {
      rep(k, p[i].first) {
        if (ao[k][j])
          x = j, y = k;
      }
    }
    if (x != -1)
      ao[y][x] = 0, ans++;
  }

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

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
vector<int> G[202];
int a[101];
int b[101];
int c[101];
int d[101];
bool used[101];
int match[101];
int n, V;

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  return res;
}

int main(void) {

  cin >> n;
  V = 2 * n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  for (int j = 0; j < n; j++) {
    cin >> c[j] >> d[j];
    for (int i = 0; i < n; i++) {
      if (a[i] < c[j] && b[i] < d[j]) {
        G[i].push_back(j + n);
        G[j + n].push_back(i);
      }
    }
  }

  cout << bipartite_matching();
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
vector<int> G[202];
int a[101];
int b[101];
int c[101];
int d[101];
bool used[202];
int match[202];
int n, V;

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  for (int v = 0; v < V; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res++;
      }
    }
  }
  return res;
}

int main(void) {

  cin >> n;
  V = 2 * n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  for (int j = 0; j < n; j++) {
    cin >> c[j] >> d[j];
    for (int i = 0; i < n; i++) {
      if (a[i] < c[j] && b[i] < d[j]) {
        G[i].push_back(j + n);
        G[j + n].push_back(i);
      }
    }
  }

  cout << bipartite_matching();
  return 0;
}
Problem p03409 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
#define fi first
#define se second
int main() {
  int n, ans = 0;
  cin >> n;
  vector<pair<int, int>> r(n);
  vector<pair<int, int>> b(n);
  for (int i = 0; i < n; i++) {
    cin >> r.at(i).fi >> r.at(i).se;
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i).se >> b.at(i).fi;
  }
  sort(r.begin(), r.end());
  sort(b.begin(), b.end());

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < n; j++) {
      if (r.at(i).fi < b.at(j).se && r.at(i).se < b.at(j).fi) {
        ans++;
        r.erase(r.begin() + i);
        b.erase(b.begin() + j);
        break;
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
#define fi first
#define se second
int main() {
  int n, ans = 0;
  cin >> n;
  vector<pair<int, int>> r(n);
  vector<pair<int, int>> b(n);
  for (int i = 0; i < n; i++) {
    cin >> r.at(i).fi >> r.at(i).se;
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i).se >> b.at(i).fi;
  }
  sort(r.begin(), r.end());
  sort(b.begin(), b.end());

  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < b.size(); j++) {
      if (r.at(i).fi < b.at(j).se && r.at(i).se < b.at(j).fi) {
        ans++;
        r.erase(r.begin() + i);
        b.erase(b.begin() + j);
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p03409 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> x(n);
  vector<vector<int>> matrix(101);
  for (int i = 0; i < 101; i++) {
    matrix[i].resize(101);
  }
  for (int i = 0; i < n; i++) {
    cin >> x[i].first >> x[i].second;
    matrix[x[i].first][x[i].second] = 1;
  }
  vector<pair<int, int>> x2(n);
  for (int i = 0; i < n; i++) {
    cin >> x2[i].first >> x2[i].second;
  }
  sort(x2.begin(), x2.end());
  int res = 0;
  for (int i = 0; i < n; i++) {
    int jj = x2[i].second;
    bool is = false;
    while (!is && jj >= 0) {
      int ii = x2[i].first;
      while (!is && ii >= 0) {
        if (matrix[ii][jj] == 1) {
          is = true;
          matrix[ii][jj] = 0;
        }
        ii--;
      }
      jj--;
    }
    res += is;
  }
  cout << res;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> x(n);
  vector<vector<int>> matrix(201);
  for (int i = 0; i < 201; i++) {
    matrix[i].resize(201);
  }
  for (int i = 0; i < n; i++) {
    cin >> x[i].first >> x[i].second;
    matrix[x[i].first][x[i].second] = 1;
  }
  vector<pair<int, int>> x2(n);
  for (int i = 0; i < n; i++) {
    cin >> x2[i].first >> x2[i].second;
  }
  sort(x2.begin(), x2.end());
  int res = 0;
  for (int i = 0; i < n; i++) {
    int jj = x2[i].second;
    bool is = false;
    while (!is && jj >= 0) {
      int ii = x2[i].first;
      while (!is && ii >= 0) {
        if (matrix[ii][jj] == 1) {
          is = true;
          matrix[ii][jj] = 0;
        }
        ii--;
      }
      jj--;
    }
    res += is;
  }
  cout << res;
  return 0;
}
Problem p03409 (C++)

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int>> RHEAP;

const int N = 210, M = 1010;

int n;
int h[N], e[N], ne[N], idx;
int match[N];
bool st[N];
PII point[N];

void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }

bool find(int u) {
  for (int i = h[u]; ~i; i = ne[i]) {
    int j = e[i];
    if (!st[j]) {
      st[j] = true;
      if (match[j] == 0 || find(match[j])) {
        match[j] = u;
        return true;
      }
    }
  }

  return false;
}

int main() {
  memset(h, -1, sizeof h);

  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> point[i].F >> point[i].S;
  for (int i = n + 1; i <= 2 * n; i++)
    cin >> point[i].F >> point[i].S;

  for (int i = 1; i <= n; i++)
    for (int j = n + 1; j <= 2 * n; j++)
      if (point[i].F < point[j].F && point[i].S < point[j].S)
        add(i, j);

  int res = 0;
  for (int i = 1; i <= n; i++) {
    memset(st, 0, sizeof st);
    if (find(i))
      res++;
  }
  cout << res << endl;
  return 0;
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int>> RHEAP;

const int N = 100010, M = 1010;

int n;
int h[N], e[N], ne[N], idx;
int match[N];
bool st[N];
PII point[N];

void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }

bool find(int u) {
  for (int i = h[u]; ~i; i = ne[i]) {
    int j = e[i];
    if (!st[j]) {
      st[j] = true;
      if (match[j] == 0 || find(match[j])) {
        match[j] = u;
        return true;
      }
    }
  }

  return false;
}

int main() {
  memset(h, -1, sizeof h);

  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> point[i].F >> point[i].S;
  for (int i = n + 1; i <= 2 * n; i++)
    cin >> point[i].F >> point[i].S;

  for (int i = 1; i <= n; i++)
    for (int j = n + 1; j <= 2 * n; j++)
      if (point[i].F < point[j].F && point[i].S < point[j].S)
        add(i, j);

  int res = 0;
  for (int i = 1; i <= n; i++) {
    memset(st, 0, sizeof st);
    if (find(i))
      res++;
  }
  cout << res << endl;
  return 0;
}
Problem p03409 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll>;
using vs = vector<string>;
#define all(v) v.begin(), v.end()
const int MAX_V = 100;
const int INF = 1e9;

int V;
vll G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  rep(i, G[v].size()) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  rep(v, V) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main() {
  cin >> V;
  vector<pair<int, int>> red, blue;
  rep(i, V) {
    int a, b;
    cin >> a >> b;
    red.push_back(make_pair(a, b));
  }
  rep(i, V) {
    int c, d;
    cin >> c >> d;
    blue.push_back(make_pair(c, d));
  }
  rep(i, V) {
    rep(j, V) {
      pair<int, int> r, b;
      r = red[i], b = blue[j];
      if (r.first < b.first && r.second < b.second)
        add_edge(i, j + V);
    }
  }
  // cout << "グラフ" << endl;
  // rep(i,V)rep(j,G[i].size()) cout<< i << " " << G[i][j]<<endl;
  cout << bipartite_matching() << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll>;
using vs = vector<string>;
#define all(v) v.begin(), v.end()
const int MAX_V = 210;
const int INF = 1e5;

int V;
vll G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs(int v) {
  used[v] = true;
  rep(i, G[v].size()) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int bipartite_matching() {
  int res = 0;
  memset(match, -1, sizeof(match));
  rep(v, V) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v))
        res++;
    }
  }
  return res;
}

int main() {
  cin >> V;
  vector<pair<int, int>> red, blue;
  rep(i, V) {
    int a, b;
    cin >> a >> b;
    red.push_back(make_pair(a, b));
  }
  rep(i, V) {
    int c, d;
    cin >> c >> d;
    blue.push_back(make_pair(c, d));
  }
  rep(i, V) {
    rep(j, V) {
      pair<int, int> r, b;
      r = red[i], b = blue[j];
      if (r.first < b.first && r.second < b.second)
        add_edge(i, j + V);
    }
  }
  // cout << "グラフ" << endl;
  // rep(i,V)rep(j,G[i].size()) cout<< i << " " << G[i][j]<<endl;
  cout << bipartite_matching() << endl;
}
Problem p03409 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#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)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 100;

class Point {
public:
  int x, y;
  bool red;

  bool operator<(const Point &p) const { return x < p.x; }
};

int N;
Point abcd[kMaxN];
int ans = 0;

set<Point> s;

signed main() {
  cin >> N;
  REP(i, N) {
    cin >> abcd[i].x >> abcd[i].y;
    abcd[i].red = true;
  }
  FOR(i, N, 2 * N) {
    cin >> abcd[i].x >> abcd[i].y;
    abcd[i].red = false;
  }

  sort(abcd, abcd + 2 * N);
  REP(i, 2 * N) {
    Point &p = abcd[i];
    if (p.red) {
      s.insert(p);
    } else {
      int max_y = -1;
      auto max_it = s.end();
      for (auto it = s.begin(); it != s.end(); ++it) {
        if (it->red && it->y < p.y && it->y > max_y) {
          max_y = it->y;
          max_it = it;
        }
      }
      if (max_y != -1) {
        s.erase(max_it);
        ++ans;
      }
    }
  }

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


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

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#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)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 100;

class Point {
public:
  int x, y;
  bool red;

  bool operator<(const Point &p) const { return x < p.x; }
};

int N;
Point abcd[kMaxN * 2];
int ans = 0;

set<Point> s;

signed main() {
  cin >> N;
  REP(i, N) {
    cin >> abcd[i].x >> abcd[i].y;
    abcd[i].red = true;
  }
  FOR(i, N, 2 * N) {
    cin >> abcd[i].x >> abcd[i].y;
    abcd[i].red = false;
  }

  sort(abcd, abcd + 2 * N);
  REP(i, 2 * N) {
    Point &p = abcd[i];
    if (p.red) {
      s.insert(p);
    } else {
      int max_y = -1;
      auto max_it = s.end();
      for (auto it = s.begin(); it != s.end(); ++it) {
        if (it->red && it->y < p.y && it->y > max_y) {
          max_y = it->y;
          max_it = it;
        }
      }
      if (max_y != -1) {
        s.erase(max_it);
        ++ans;
      }
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define PB push_back
#define MP make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

int main() {
  int n, ans = 0;
  bool red[105][105] = {};
  vector<pair<int, int>> blue;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    red[a][b] = true;
  }
  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    blue.PB(MP(c, d));
  }
  sort(blue.begin(), blue.end());
  for (int i = 0; i < n; i++) {
    int x = -1, y = -1;
    pair<int, int> t = blue[i];
    for (int j = 0; j < t.second; j++) {
      for (int k = 0; k < t.first; k++) {
        if (red[k][j]) {
          x = k;
          y = j;
        }
      }
    }
    if (x != -1 && y != -1) {
      ans++;
      red[x][y] = false;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define PB push_back
#define MP make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

int main() {
  int n, ans = 0;
  bool red[205][205] = {};
  vector<pair<int, int>> blue;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    red[a][b] = true;
  }
  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    blue.PB(MP(c, d));
  }
  sort(blue.begin(), blue.end());
  for (int i = 0; i < n; i++) {
    int x = -1, y = -1;
    pair<int, int> t = blue[i];
    for (int j = 0; j < t.second; j++) {
      for (int k = 0; k < t.first; k++) {
        if (red[k][j]) {
          x = k;
          y = j;
        }
      }
    }
    if (x != -1 && y != -1) {
      ans++;
      red[x][y] = false;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03409 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;
int N;
vector<int> G[202];
bool used[101];
int match[101];

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int mat() {
  int ans = 0;
  memset(match, -1, sizeof(match));
  for (int v = 1; v <= 2 * N; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        ans++;
      }
    }
  }
  return ans;
}

int main() {
  cin >> N;
  vector<P> R(N + 1), B(N + 1);
  for (int i = 1; i <= N; i++) {
    int a, b;
    cin >> a >> b;
    R[i] = P(a, b);
  }
  for (int i = 1; i <= N; i++) {
    int a, b;
    cin >> a >> b;
    B[i] = P(a, b);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (R[i].first < B[j].first && R[i].second < B[j].second) {
        G[i].push_back(j + N);
        G[j + N].push_back(i);
      }
    }
  }
  cout << mat() << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> P;
int N;
vector<int> G[202];
bool used[202];
int match[202];

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}

int mat() {
  int ans = 0;
  memset(match, -1, sizeof(match));
  for (int v = 1; v <= 2 * N; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        ans++;
      }
    }
  }
  return ans;
}

int main() {
  cin >> N;
  vector<P> R(N + 1), B(N + 1);
  for (int i = 1; i <= N; i++) {
    int a, b;
    cin >> a >> b;
    R[i] = P(a, b);
  }
  for (int i = 1; i <= N; i++) {
    int a, b;
    cin >> a >> b;
    B[i] = P(a, b);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (R[i].first < B[j].first && R[i].second < B[j].second) {
        G[i].push_back(j + N);
        G[j + N].push_back(i);
      }
    }
  }
  cout << mat() << endl;
}
Problem p03409 (C++)

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

using namespace std;

typedef pair<int, int> P;

bool comp(P a, P b) {
  if (a.second > b.second)
    return true;
  else if (a.second == b.second && a.first > b.first)
    return true;
}

int main() {
  int n;
  cin >> n;
  P *ab = new P[n];
  for (int i = 0; i < n; i++)
    cin >> ab[i].first >> ab[i].second;

  P *cd = new P[n];
  for (int i = 0; i < n; i++)
    cin >> cd[i].first >> cd[i].second;

  sort(ab, ab + n, comp);
  sort(cd, cd + n);

  int ans = 0;
  vector<bool> check(n, false);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (ab[j].first < cd[i].first && ab[j].second < cd[i].second &&
          !check[j]) {
        check[j] = true;
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> P;

bool comp(P a, P b) {
  if (a.second > b.second)
    return true;
  else if (a.second == b.second && a.first > b.first)
    return true;
  else {
    return false;
  }
}

int main() {
  int n;
  cin >> n;
  P *ab = new P[n];
  for (int i = 0; i < n; i++)
    cin >> ab[i].first >> ab[i].second;

  P *cd = new P[n];
  for (int i = 0; i < n; i++)
    cin >> cd[i].first >> cd[i].second;

  sort(ab, ab + n, comp);
  sort(cd, cd + n);

  int ans = 0;
  vector<bool> check(n, false);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (ab[j].first < cd[i].first && ab[j].second < cd[i].second &&
          !check[j]) {
        check[j] = true;
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;
}
Problem p03411 (C++)

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

using namespace std;

struct node {
  int x, y;
} ac[110], bc[110];

int vis[110][110];
int flag[110];
int pri[110];
int n;

bool find(int i) {
  int j;
  for (j = 1; j <= n; j++) {
    if (vis[ac[i].x][bc[j].x] && !flag[j]) {
      flag[j] = 1;
      if (pri[j] == -1 || find(pri[j])) {
        pri[j] = i;
        return true;
      }
    }
  }
  return false;
}

int main() {
  scanf("%d", &n);
  memset(vis, 0, sizeof(vis));
  memset(pri, -1, sizeof(pri));
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &ac[i].x, &ac[i].y);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &bc[i].x, &bc[i].y);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (ac[i].x < bc[j].x && ac[i].y < bc[j].y) {
        vis[ac[i].x][bc[j].x] = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(flag, 0, sizeof(flag));
    if (find(i))
      ans += 1;
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

struct node {
  int x, y;
} ac[110], bc[110];

int vis[210][210];
int flag[210];
int pri[210];
int n;

bool find(int i) {
  int j;
  for (j = 1; j <= n; j++) {
    if (vis[ac[i].x][bc[j].x] && !flag[j]) {
      flag[j] = 1;
      if (pri[j] == -1 || find(pri[j])) {
        pri[j] = i;
        return true;
      }
    }
  }
  return false;
}

int main() {
  scanf("%d", &n);
  memset(vis, 0, sizeof(vis));
  memset(pri, -1, sizeof(pri));
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &ac[i].x, &ac[i].y);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &bc[i].x, &bc[i].y);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (ac[i].x < bc[j].x && ac[i].y < bc[j].y) {
        vis[ac[i].x][bc[j].x] = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(flag, 0, sizeof(flag));
    if (find(i))
      ans += 1;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03411 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
P r[105], b[105];
bool R[105];
int ans;
int mr2;
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i].first >> r[i].second;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].first >> b[i].second;
  }
  sort(r, r + n);
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    int j = 0;
    mr2 = -1;
    int l = -1;
    while (b[i].first > r[j].first) {
      j++;
    }
    for (int k = 0; k < j; k++) {
      if (b[i].second > r[k].second && r[k].second > mr2 && R[k] == false) {
        mr2 = r[k].second;
        l = k;
      }
    }
    if (l != -1) {
      R[l] = true;
      ans++;
      // cout<<"h"<<endl;
    }
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
P r[105], b[105];
bool R[105];
int ans;
int mr2;
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i].first >> r[i].second;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].first >> b[i].second;
  }
  sort(r, r + n);
  sort(b, b + n);
  for (int i = 0; i < n; i++) {
    int j = 0;
    mr2 = -1;
    int l = -1;
    while (b[i].first > r[j].first && j < n) {
      j++;
    }
    for (int k = 0; k < j; k++) {
      if (b[i].second > r[k].second && r[k].second > mr2 && R[k] == false) {
        mr2 = r[k].second;
        l = k;
      }
    }
    if (l != -1) {
      R[l] = true;
      ans++;
      // cout<<"h"<<endl;
    }
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}
Problem p03411 (C++)

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

using namespace std;

typedef long long LL;
typedef pair<int, int> P2;
typedef pair<pair<int, int>, int> P3;
typedef pair<pair<int, int>, pair<int, int>> P4;
#define PB(a) push_back(a)
#define MP(a, b) make_pair((a), (b))
#define M3P(a, b, c) make_pair(make_pair((a), (b)), (c))
#define M4P(a, b, c, d) make_pair(make_pair((a), (b)), make_pair((c), (d)))
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)

const int MC = 111;
int N;
P2 r[MC], b[MC];
bool c[MC];

int main() {
  cin >> N;
  repp(i, 0, N) {
    int x, y;
    cin >> x >> y;
    r[i] = MP(x, y);
  }
  repp(i, 0, N) {
    int x, y;
    cin >> x >> y;
    b[i] = MP(x, y);
  }
  sort(r, r + N);
  sort(b, b + N);
  int ans = 0;
  int pr = 0, pb = 0;
  r[N] = b[N] = MP(1234567, 1234567);
  while (pr < N || pb < N) {
    if (r[pr].first < b[pb].first) {
      c[r[pr].second] = 1;
      // cerr << "r " << r[pr].first << ' ' << r[pr].second << endl;
      ++pr;
    } else {
      repm(k, b[pb].second, -1) {
        if (c[k]) {
          c[k] = 0;
          ++ans;
          break;
        }
      }
      // cerr << "b " << b[pb].first << ' ' << b[pb].second << endl;
      ++pb;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> P2;
typedef pair<pair<int, int>, int> P3;
typedef pair<pair<int, int>, pair<int, int>> P4;
#define PB(a) push_back(a)
#define MP(a, b) make_pair((a), (b))
#define M3P(a, b, c) make_pair(make_pair((a), (b)), (c))
#define M4P(a, b, c, d) make_pair(make_pair((a), (b)), make_pair((c), (d)))
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)

const int MC = 111;
int N;
P2 r[MC], b[MC];
bool c[MC * 2];

int main() {
  cin >> N;
  repp(i, 0, N) {
    int x, y;
    cin >> x >> y;
    r[i] = MP(x, y);
  }
  repp(i, 0, N) {
    int x, y;
    cin >> x >> y;
    b[i] = MP(x, y);
  }
  sort(r, r + N);
  sort(b, b + N);
  int ans = 0;
  int pr = 0, pb = 0;
  r[N] = b[N] = MP(1234567, 1234567);
  while (pr < N || pb < N) {
    if (r[pr].first < b[pb].first) {
      c[r[pr].second] = 1;
      // cerr << "r " << r[pr].first << ' ' << r[pr].second << endl;
      ++pr;
    } else {
      repm(k, b[pb].second, -1) {
        if (c[k]) {
          c[k] = 0;
          ++ans;
          break;
        }
      }
      // cerr << "b " << b[pb].first << ' ' << b[pb].second << endl;
      ++pb;
    }
  }
  cout << ans << endl;
  return 0;
}