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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ab(x) ((x) > 0 ? (x) : (x) * (-1))
#define ll long long
using namespace std;
const int N = 5005;
int n, now, a[N];
ll s = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s += ab(a[i] - a[i - 1]);
  }
  s += ab(a[n]);
  for (int i = 1; i <= n; i++) {
    now =
        s - ab(a[i] - a[i - 1]) - ab(a[i + 1] - a[i]) + ab(a[i + 1] - a[i - 1]);

    cout << now << "\n";
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define ab(x) ((x) > 0 ? (x) : (x) * (-1))
#define ll long long
using namespace std;
const int N = 100005;
int n, now, a[N];
ll s = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s += ab(a[i] - a[i - 1]);
  }
  s += ab(a[n]);
  for (int i = 1; i <= n; i++) {
    now =
        s - ab(a[i] - a[i - 1]) - ab(a[i + 1] - a[i]) + ab(a[i + 1] - a[i - 1]);

    cout << now << "\n";
  }
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
using namespace std;
const int MAX = 10010;
int p[MAX], d1[MAX], d2[MAX], sum, n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &p[i]);
  for (int i = 0; i <= n; i++)
    d1[i] = abs(p[i + 1] - p[i]), sum += d1[i];
  for (int i = 0; i < n; i++)
    d2[i] = abs(p[i + 2] - p[i]);
  for (int i = 0; i < n; i++) {
    // printf("%d %d %d\n",sum,d1[i]+d1[i+1],d2[i]);
    printf("%d\n", sum - d1[i] - d1[i + 1] + d2[i]);
  }
}


Fixed submission:
#include <algorithm>
#include <stdio.h>
using namespace std;
const int MAX = 100010;
int p[MAX], d1[MAX], d2[MAX], sum, n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &p[i]);
  for (int i = 0; i <= n; i++)
    d1[i] = abs(p[i + 1] - p[i]), sum += d1[i];
  for (int i = 0; i < n; i++)
    d2[i] = abs(p[i + 2] - p[i]);
  for (int i = 0; i < n; i++) {
    // printf("%d %d %d\n",sum,d1[i]+d1[i+1],d2[i]);
    printf("%d\n", sum - d1[i] - d1[i + 1] + d2[i]);
  }
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 5678;
int a[MAXN];

int main() {
  int N;
  while (~scanf("%d", &N)) {
    int sum = 0, prev = 0;
    for (int i = 1; i <= N; i++) {
      scanf("%d", &a[i]);
      sum += abs(prev - a[i]);
      prev = a[i];
    }
    sum += abs(prev);
    a[N + 1] = 0;
    for (int i = 1; i <= N; i++) {
      int pre_dis = abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]);
      printf("%d\n", sum - pre_dis + abs(a[i - 1] - a[i + 1]));
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
int a[MAXN];

int main() {
  int N;
  while (~scanf("%d", &N)) {
    int sum = 0, prev = 0;
    for (int i = 1; i <= N; i++) {
      scanf("%d", &a[i]);
      sum += abs(prev - a[i]);
      prev = a[i];
    }
    sum += abs(prev);
    a[N + 1] = 0;
    for (int i = 1; i <= N; i++) {
      int pre_dis = abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]);
      printf("%d\n", sum - pre_dis + abs(a[i - 1] - a[i + 1]));
    }
  }
  return 0;
}
Problem p03403 (C++)

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

#define MAX 3

int main() {
  int N, A[MAX + 2];
  cin >> N;
  A[0] = 0;
  A[N + 1] = 0;
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    sum += abs(A[i] - A[i - 1]);
  }
  sum += abs(A[N + 1] - A[N]);
  for (int i = 1; i <= N; i++) {
    cout << sum - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) +
                abs(A[i + 1] - A[i - 1])
         << endl;
  }
  return 0;
}

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

#define MAX 100000

int main() {
  int N, A[MAX + 2];
  cin >> N;
  A[0] = 0;
  A[N + 1] = 0;
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    sum += abs(A[i] - A[i - 1]);
  }
  sum += abs(A[N + 1] - A[N]);
  for (int i = 1; i <= N; i++) {
    cout << sum - abs(A[i + 1] - A[i]) - abs(A[i] - A[i - 1]) +
                abs(A[i + 1] - A[i - 1])
         << endl;
  }
  return 0;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  long long n, a, sum = 0;
  cin >> n;
  int test[1001] = {0};
  for (int h = 1; h <= n; h++) {
    cin >> a;
    test[h] = a;
  }
  for (int h = 0; h <= n; h++) {
    sum += abs(test[h] - test[h + 1]);
  }
  for (int h = 1; h <= n; h++) {
    if (test[h - 1] <= test[h] && test[h] <= test[h + 1]) {
      cout << sum << endl;
    } else if (test[h - 1] >= test[h] && test[h] >= test[h + 1]) {
      cout << sum << endl;
    } else {
      cout << sum - abs(test[h] - test[h + 1]) - abs(test[h - 1] - test[h]) +
                  abs(test[h - 1] - test[h + 1])
           << endl;
    }
  }
  cin >> n;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  long long n, a, sum = 0;
  cin >> n;
  int test[100001] = {0};
  for (int h = 1; h <= n; h++) {
    cin >> a;
    test[h] = a;
  }
  for (int h = 0; h <= n; h++) {
    sum += abs(test[h] - test[h + 1]);
  }
  for (int h = 1; h <= n; h++) {
    if (test[h - 1] <= test[h] && test[h] <= test[h + 1]) {
      cout << sum << endl;
    } else if (test[h - 1] >= test[h] && test[h] >= test[h + 1]) {
      cout << sum << endl;
    } else {
      cout << sum - abs(test[h] - test[h + 1]) - abs(test[h - 1] - test[h]) +
                  abs(test[h - 1] - test[h + 1])
           << endl;
    }
  }
  cin >> n;
}
Problem p03403 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

const int maxN = 1e2 + 10, oo = 23041997, modP = 1e7, maxC = 50;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define F first
#define S second
#define PB push_back
#define LL long long
#define BIT(x, i) ((x >> i) & 1)
#define PINT pair<int, int>

int a[maxN], n, res;

int dist(int i, int j) { return (int)abs(a[i] - a[j]); }

int main() {
  cin >> n;
  FORU(i, 1, n) cin >> a[i];
  a[0] = a[n + 1] = 0;
  FORU(i, 0, n)
  res += dist(i, i + 1);
  FORU(i, 1, n)
  cout << res - dist(i, i - 1) - dist(i, i + 1) + dist(i - 1, i + 1) << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

const int maxN = 1e5 + 10, oo = 23041997, modP = 1e7, maxC = 50;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define F first
#define S second
#define PB push_back
#define LL long long
#define BIT(x, i) ((x >> i) & 1)
#define PINT pair<int, int>

int a[maxN], n, res;

int dist(int i, int j) { return (int)abs(a[i] - a[j]); }

int main() {
  cin >> n;
  FORU(i, 1, n) cin >> a[i];
  a[0] = a[n + 1] = 0;
  FORU(i, 0, n)
  res += dist(i, i + 1);
  FORU(i, 1, n)
  cout << res - dist(i, i - 1) - dist(i, i + 1) + dist(i - 1, i + 1) << endl;
}
Problem p03405 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;

const int maxn = 1005;
const int mod = 1000000007;
struct edge {
  int u, v, w;
  bool operator<(const edge &e) const { return w < e.w; }
} e[maxn];
int pa[maxn], n, m, le, eq, ge, ans;
ll now, X;

inline int power(int x, int p) {
  int res = 1;
  while (p) {
    if (p & 1)
      res = 1ll * res * x % mod;
    x = 1ll * x * x % mod;
    p >>= 1;
  }
  return res;
}

inline int getpa(int x) { return pa[x] == x ? x : pa[x] = getpa(pa[x]); }

ll MST() {
  ll res = 0;
  rep(i, 1, n) pa[i] = i;
  rep(i, 0, m) if (getpa(e[i].u) != getpa(e[i].v)) {
    pa[getpa(e[i].u)] = getpa(e[i].v);
    res += e[i].w;
  }
  return res;
}

int main() {
  scanf("%d%d", &n, &m);
  scanf("%lld", &X);
  rep(i, 1, m) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  sort(e + 1, e + m + 1);
  rep(i, 1, m) {
    e[0] = e[i];
    now = MST();
    if (now < X)
      le++;
    if (now == X)
      eq++;
    if (now > X)
      ge++;
  }
  if (!eq)
    return puts("0"), 0;
  ans = (le ? 2ll * (power(2, eq) + mod - 1) : power(2, eq) + mod - 2) *
        power(2, ge) % mod;
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;

const int maxn = 2005;
const int mod = 1000000007;
struct edge {
  int u, v, w;
  bool operator<(const edge &e) const { return w < e.w; }
} e[maxn];
int pa[maxn], n, m, le, eq, ge, ans;
ll now, X;

inline int power(int x, int p) {
  int res = 1;
  while (p) {
    if (p & 1)
      res = 1ll * res * x % mod;
    x = 1ll * x * x % mod;
    p >>= 1;
  }
  return res;
}

inline int getpa(int x) { return pa[x] == x ? x : pa[x] = getpa(pa[x]); }

ll MST() {
  ll res = 0;
  rep(i, 1, n) pa[i] = i;
  rep(i, 0, m) if (getpa(e[i].u) != getpa(e[i].v)) {
    pa[getpa(e[i].u)] = getpa(e[i].v);
    res += e[i].w;
  }
  return res;
}

int main() {
  scanf("%d%d", &n, &m);
  scanf("%lld", &X);
  rep(i, 1, m) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  sort(e + 1, e + m + 1);
  rep(i, 1, m) {
    e[0] = e[i];
    now = MST();
    if (now < X)
      le++;
    if (now == X)
      eq++;
    if (now > X)
      ge++;
  }
  if (!eq)
    return puts("0"), 0;
  ans = (le ? 2ll * (power(2, eq) + mod - 1) : power(2, eq) + mod - 2) *
        power(2, ge) % mod;
  printf("%d\n", ans);
  return 0;
}
Problem p03405 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long LL;

const int N = 1050;
const int M = 2050;
const int mod = 1000000007;

struct Edge {
  int u, v, w;
  bool operator<(const Edge &e) const { return w < e.w; }
} e[N];

int fa[N];

int Find(int x) { return fa[x] ? fa[x] = Find(fa[x]) : x; }
bool Union(int x, int y) {
  if ((x = Find(x)) != (y = Find(y))) {
    fa[x] = y;
    return true;
  }
  return false;
}

LL pow_mod(LL x, int p) {
  LL ans = 1;
  for (; p; p >>= 1, (x *= x) %= mod)
    if (p & 1)
      (ans *= x) %= mod;
  return ans;
}

int main() {
  int n, m;
  LL x;
  scanf("%d%d%lld", &n, &m, &x);
  if (n <= 2) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  std::sort(e, e + m);
  int s1 = 0, s2 = 0;
  for (int i = 0; i < m; ++i) {
    memset(fa, 0, sizeof fa);
    LL ans = e[i].w * Union(e[i].u, e[i].v);
    for (int j = 0; j < m; ++j)
      ans += e[j].w * Union(e[j].u, e[j].v);
    if (ans < x)
      ++s1;
    if (ans <= x)
      ++s2;
    // s2 > s1
  }
  printf("%lld\n", (pow_mod(2, std::min(m, m - s1 + 1)) -
                    pow_mod(2, std::min(m, m - s2 + 1)) + mod) %
                       mod);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long LL;

const int N = 1050;
const int M = 2050;
const int mod = 1000000007;

struct Edge {
  int u, v, w;
  bool operator<(const Edge &e) const { return w < e.w; }
} e[M];

int fa[N];

int Find(int x) { return fa[x] ? fa[x] = Find(fa[x]) : x; }
bool Union(int x, int y) {
  if ((x = Find(x)) != (y = Find(y))) {
    fa[x] = y;
    return true;
  }
  return false;
}

LL pow_mod(LL x, int p) {
  LL ans = 1;
  for (; p; p >>= 1, (x *= x) %= mod)
    if (p & 1)
      (ans *= x) %= mod;
  return ans;
}

int main() {
  int n, m;
  LL x;
  scanf("%d%d%lld", &n, &m, &x);
  if (n <= 2) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
  std::sort(e, e + m);
  int s1 = 0, s2 = 0;
  for (int i = 0; i < m; ++i) {
    memset(fa, 0, sizeof fa);
    LL ans = e[i].w * Union(e[i].u, e[i].v);
    for (int j = 0; j < m; ++j)
      ans += e[j].w * Union(e[j].u, e[j].v);
    if (ans < x)
      ++s1;
    if (ans <= x)
      ++s2;
    // s2 > s1
  }
  printf("%lld\n", (pow_mod(2, std::min(m, m - s1 + 1)) -
                    pow_mod(2, std::min(m, m - s2 + 1)) + mod) %
                       mod);
  return 0;
}
Problem p03407 (Python)

Buggy submission (status: Runtime Error):
A, B, C = input()
if A + B * 2 >= C:
    print("Yes")
else:
    print("No")


Fixed submission:
A, B, C = map(int, input().split())
if A + B >= C:
    print("Yes")
else:
    print("No")
Problem p03407 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem A

if __name__ == "__main__":
    A, B, C = list(map(int, input().split()))

    if (A + B) >= C:
        print("Yes")
    else:
        print("No")
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem A

if __name__ == "__main__":
    A, B, C = list(map(int, input().split()))

    if (A + B) >= C:
        print("Yes")
    else:
        print("No")


Fixed submission:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem A

if __name__ == "__main__":
    A, B, C = list(map(int, input().split()))

    if (A + B) >= C:
        print("Yes")
    else:
        print("No")
Problem p03407 (Python)

Buggy submission (status: Runtime Error):
a, b, c = map(int(input().split()))

if a + b >= c:
    print("Yes")
else:
    print("No")


Fixed submission:
a, b, c = map(int, input().split())

if a + b >= c:
    print("Yes")
else:
    print("No")
Problem p03407 (C++)

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<int>> matrix;

#define SET(Ar, val) memset(Ar, val, sizeof(Ar))
#define rep(i, val, n) for (int i = val; i < n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define M 1000000007

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a, T b, T MOD) {
  T ans = 1;
  while (b != 0) {
    if (b % 2 == 1)
      ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return ans;
}

void init() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b >= c)
    cout << "Yes";
  else
    cout << "No";
}

int main() {
  clock_t time1 = clock();
#ifndef ONLINE_JUDGE
  freopen("abc_091.in", "r", stdin);
#else
// ONLINE_JUDGE
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  clock_t time2 = clock();
  cerr << "Time: " << (double)(time2 - time1) / CLOCKS_PER_SEC << " seconds"
       << endl;
  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<int>> matrix;

#define SET(Ar, val) memset(Ar, val, sizeof(Ar))
#define rep(i, val, n) for (int i = val; i < n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define M 1000000007

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a, T b, T MOD) {
  T ans = 1;
  while (b != 0) {
    if (b % 2 == 1)
      ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return ans;
}

void init() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b >= c)
    cout << "Yes";
  else
    cout << "No";
}

int main() {
  clock_t time1 = clock();
  /*#ifndef ONLINE_JUDGE
  //freopen("abc_091.in","r",stdin);
  #else
  //ONLINE_JUDGE
  #endif*/
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  clock_t time2 = clock();
  cerr << "Time: " << (double)(time2 - time1) / CLOCKS_PER_SEC << " seconds"
       << endl;
  return 0;
}
Problem p03407 (Python)

Buggy submission (status: Runtime Error):
A, B, C = map(int, input())
print("Yes" if A + B >= C else "No")


Fixed submission:
A, B, C = map(int, input().split())
print("Yes" if A + B >= C else "No")
Problem p03408 (C++)

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

int main() {
  int N, M;
  string s[N], t[M];

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

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

  int ans = 0;

  for (int i = 0; i < N; i++) {
    int temp = 0;
    for (int j = i; j < N; j++) {
      if (s[i] == s[j]) {
        temp++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (s[i] == t[j]) {
        temp--;
      }
    }
    if (temp >= ans) {
      ans = temp;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N, M;
  string s[101], t[101];

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

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

  int ans = 0;

  for (int i = 0; i < N; i++) {
    int temp = 0;
    for (int j = i; j < N; j++) {
      if (s[i] == s[j]) {
        temp++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (s[i] == t[j]) {
        temp--;
      }
    }
    if (temp >= ans) {
      ans = temp;
    }
  }

  cout << ans << endl;

  return 0;
}
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);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  cin >> M;
  vector<string> T(M);
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    for (int j = 0; j < N - i; j++) {
      if (S[i] == S[i + j]) {
        cnt++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (S[i] == S[j]) {
        cnt--;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}


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

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

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;

  vector<string> blue(N);

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

  int M;
  cin >> M;

  vector<string> red(M);

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

  int point = 0;

  for (int i = 0; i < N; i++) {
    int p = 0;
    for (int j = 0; j < N; j++) {
      if (blue[i] == blue[j])
        p++;
    }
    for (int j = 0; j < M; j++) {
      if (blue[i] == blue[j])
        p--;
    }
    if (p > point)
      point = p;
  }

  cout << point << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;

  vector<string> blue(N);

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

  int M;
  cin >> M;

  vector<string> red(M);

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

  int point = 0;

  for (int i = 0; i < N; i++) {
    int p = 0;
    for (int j = 0; j < N; j++) {
      if (blue[i] == blue[j])
        p++;
    }
    for (int j = 0; j < M; j++) {
      if (blue[i] == red[j])
        p--;
    }
    if (p > point)
      point = p;
  }

  cout << point << endl;

  return 0;
}
Problem p03408 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

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

  vector<int> sum(N);
  for (int i = 0; i < N; i++) {
    string a = S.at(i);
    for (int j = 0; j < N; j++) {
      if (S.at(j) == a) {
        sum.at(i)++;
      }
      if (T.at(j) == a) {
        sum.at(i)--;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < N; i++) {
    if (max < sum.at(i)) {
      max = sum.at(i);
    }
  }
  if (max > 0) {
    cout << max << endl;
  } else {
    cout << 0 << endl;
  }
}


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }

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

  vector<int> sum(N);
  for (int i = 0; i < N; i++) {
    string a = S.at(i);
    for (int j = 0; j < N; j++) {
      if (S.at(j) == a) {
        sum.at(i)++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (T.at(j) == a) {
        sum.at(i)--;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < N; i++) {
    if (max < sum.at(i)) {
      max = sum.at(i);
    }
  }
  if (max > 0) {
    cout << max << endl;
  } else {
    cout << 0 << endl;
  }
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, rez, r;
string s[100], t[100];
int main() {
  std::cin.sync_with_stdio(false);
  std::cin.tie(0);
  cin >> n;
  i = 0;
  while (i < n) {
    cin >> s[i];
    i++;
  }
  cin >> m;
  i = 0;
  while (i < m) {
    cin >> t[i];
    i++;
  }
  sort(s, s + n);
  sort(t, t + m);
  i = 0;
  rez = 0;
  while (i < n) {
    r = 1;
    j = 0;
    while (j < m) {
      if (t[j] == s[i]) {
        r--;
      }
      j++;
    }
    while (s[i + 1] == s[i]) {
      r++;
      i++;
    }
    rez = max(rez, r);
    i++;
  }
  cout << rez;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, rez, r;
string s[200], t[200];
int main() {
  std::cin.sync_with_stdio(false);
  std::cin.tie(0);
  cin >> n;
  i = 0;
  while (i < n) {
    cin >> s[i];
    i++;
  }
  cin >> m;
  i = 0;
  while (i < m) {
    cin >> t[i];
    i++;
  }
  sort(s, s + n);
  sort(t, t + m);
  i = 0;
  rez = 0;
  while (i < n) {
    r = 1;
    j = 0;
    while (j < m) {
      if (t[j] == s[i]) {
        r--;
      }
      j++;
    }
    while (s[i + 1] == s[i]) {
      r++;
      i++;
    }
    rez = max(rez, r);
    i++;
  }
  cout << rez;
  return 0;
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, M;
  cin >> N;
  string s[N];
  for (int i = 0; i < N; i++)
    cin >> s[i];
  cin >> M;
  string t[M];
  for (int i = 0; i < M; i++)
    cin >> t[i];
  int sa[N];
  for (int i = 0; i < N; i++)
    sa[i] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < i; i++) {
      if (s[i] == s[j]) {
        sa[j]++;
        sa[i]--;
        break;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (sa[i] > 0) {
      for (int j = 0; j < M; j++) {
        if (s[i] == t[j])
          sa[i]--;
      }
    }
  }
  int Ans = 0;
  for (int i = 0; i < N; i++) {
    if (Ans < sa[i])
      Ans = sa[i];
  }
  cout << Ans;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, M;
  cin >> N;
  string s[N];
  for (int i = 0; i < N; i++)
    cin >> s[i];
  cin >> M;
  string t[M];
  for (int i = 0; i < M; i++)
    cin >> t[i];
  int sa[N];
  for (int i = 0; i < N; i++)
    sa[i] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j]) {
        sa[j]++;
        sa[i]--;
        break;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (sa[i] > 0) {
      for (int j = 0; j < M; j++) {
        if (s[i] == t[j])
          sa[i]--;
      }
    }
  }
  int Ans = 0;
  for (int i = 0; i < N; i++) {
    if (Ans < sa[i])
      Ans = sa[i];
  }
  cout << Ans;
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s[i];

  int M;
  cin >> M;
  vector<string> t(N);
  rep(i, M) cin >> t[i];

  int ans = 0;

  rep(i, N) {
    int score = 0;
    rep(j, N) if (s[j] == s[i]) score++;
    rep(j, M) if (t[j] == s[i]) score--;

    ans = max(ans, score);
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s[i];

  int M;
  cin >> M;
  vector<string> t(M);
  rep(i, M) cin >> t[i];

  int ans = 0;

  rep(i, N) {
    int score = 0;
    rep(j, N) if (s[j] == s[i]) score++;
    rep(j, M) if (t[j] == s[i]) score--;

    ans = max(ans, score);
  }

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

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

using namespace std;

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  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);
  }
  int ans = 0;

  for (int i = 0; i < N; i++) {
    string str = s.at(i);
    int tmp = 1;
    for (int j = 0; j < N; j++) {
      if (i == j) {
        continue;
      }
      if (str == s.at(j)) {
        tmp++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (str == t.at(j)) {
        tmp--;
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  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);
  }
  int ans = 0;

  for (int i = 0; i < N; i++) {
    string str = s.at(i);
    int tmp = 1;
    for (int j = 0; j < N; j++) {
      if (i == j) {
        continue;
      }
      if (str == s.at(j)) {
        tmp++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (str == t.at(j)) {
        tmp--;
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
Problem p03408 (C++)

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

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

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

  int M;
  cin >> M;

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

  vector<int> sum(N);
  for (int i = 0; i < N; i++) {
    int sum0 = 0;
    for (int j = 0; j < N; j++) {
      if (vecs.at(i) == vecs.at(j)) {
        sum0++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (vecs.at(i) == vect.at(j)) {
        sum0--;
      }
    }
    sum.at(i) = sum0;
  }

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

  if (sum.at(N + M - 1) > 0) {
    cout << sum.at(N + M - 1) << endl;
  } else {
    cout << "0" << endl;
  }
}

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

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

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

  int M;
  cin >> M;

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

  vector<int> sum(N);
  for (int i = 0; i < N; i++) {
    int sum0 = 0;
    for (int j = 0; j < N; j++) {
      if (vecs.at(i) == vecs.at(j)) {
        sum0++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (vecs.at(i) == vect.at(j)) {
        sum0--;
      }
    }
    sum.at(i) = sum0;
  }

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

  if (sum.at(N - 1) > 0) {
    cout << sum.at(N - 1) << endl;
  } else {
    cout << "0" << endl;
  }
}
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);
  int i;

  for (i = 0; i < n; i++) {
    cin >> s[i];
  }

  cin >> m;
  vector<string> t(m);
  for (i = 0; i < m; i++) {
    cin >> t[i];
  }

  int j;
  string say;
  int ans = 0;
  int count = 0;
  for (i = 0; i < n; i++) {
    count = 0;
    say = s[i];
    for (j = 0; j < n; j++) {
      if (say == s[j])
        count++;
    }
    for (j = 0; j < m; j++) {
      if (say == t[i])
        count--;
    }
    ans = max(ans, count);
  }

  cout << ans << endl;
}

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

int main() {
  int n, m;

  cin >> n;

  vector<string> s(n);
  int i;

  for (i = 0; i < n; i++) {
    cin >> s[i];
  }

  cin >> m;
  vector<string> t(m);
  for (i = 0; i < m; i++) {
    cin >> t[i];
  }

  int j;
  string say;
  int ans = 0;
  int count = 0;
  for (i = 0; i < n; i++) {
    count = 0;
    say = s[i];
    for (j = 0; j < n; j++) {
      if (say == s[j])
        count++;
    }
    for (j = 0; j < m; j++) {
      if (say == t[j])
        count--;
    }
    ans = max(ans, count);
  }

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

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

int main() {
  int N, M, ans = 0;
  int tmp = 0;
  string a;
  vector<string> s, t;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    s.push_back(a);
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> a;
    t.push_back(a);
  }

  for (int i = 0; i < N; i++) {
    tmp = 1;
    for (int j = 0; j < N; j++) {
      if (s[i] == t[j])
        tmp--;
    }
    for (int j = 0; j < N; j++) {
      if (i != j && s[i] == s[j])
        tmp++;
    }
    if (ans < tmp)
      ans = tmp;
  }
  cout << ans << endl;
}

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

int main() {
  int N, M, ans = 0;
  int tmp = 0;
  string a;
  vector<string> s, t;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    s.push_back(a);
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> a;
    t.push_back(a);
  }

  for (int i = 0; i < N; i++) {
    tmp = 1;
    for (int j = 0; j < M; j++) {
      if (s[i] == t[j])
        tmp--;
    }
    for (int j = 0; j < N; j++) {
      if (i != j && s[i] == s[j])
        tmp++;
    }
    if (ans < tmp)
      ans = tmp;
  }
  cout << ans << endl;
}
Problem p03408 (C++)

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

int main() {
  int blue, red;
  vector<string> blue_str(100), red_str(100);
  vector<int> blue_count(100), red_count(100);

  cin >> blue;
  for (int i = 0; i < blue; i++) {
    cin >> blue_str.at(i);
  }

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

  /* count the number of each string. */
  for (int h = 0; h < blue; h++) {
    int b_count = 0;
    for (int i = 0; i < blue; i++) {
      if (blue_str.at(h) == blue_str.at(i)) {
        b_count++;
      }
    }
    blue_count.at(h) = b_count;
  }

  for (int h = 0; h < red; h++) {
    int r_count = 0;
    for (int i = 0; i < red; i++) {
      if (red_str.at(h) == red_str.at(i)) {
        r_count++;
      }
    }
    red_count.at(h) = r_count;
  }

  /* subtract */
  int max = 0;
  for (int h = 0; h < 100; h++) {
    for (int i = 0; i < blue; i++) {
      if (blue_str.at(h) == red_str.at(i)) {
        blue_count.at(h) -= red_count.at(i);
        break;
      }
    }
    if (max < blue_count.at(h)) {
      max = blue_count.at(h);
    }
  }
  cout << max << endl;

  for (int i = 0; i < 100; i++) {
    cout << blue_count.at(i) << " " << red_count.at(i) << endl;
  }
  for (int i = 0; i < red + blue; i++) {
    cout << red_str.at(i) << blue_str.at(i) << endl;
  }
}

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

int main() {
  int blue, red;
  vector<string> blue_str(100), red_str(100);
  vector<int> blue_count(100), red_count(100);

  cin >> blue;
  for (int i = 0; i < blue; i++) {
    cin >> blue_str.at(i);
  }

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

  /* count the number of each string. */
  for (int h = 0; h < blue; h++) {
    int b_count = 0;
    for (int i = 0; i < blue; i++) {
      if (blue_str.at(h) == blue_str.at(i)) {
        b_count++;
      }
    }
    blue_count.at(h) = b_count;
  }

  for (int h = 0; h < red; h++) {
    int r_count = 0;
    for (int i = 0; i < red; i++) {
      if (red_str.at(h) == red_str.at(i)) {
        r_count++;
      }
    }
    red_count.at(h) = r_count;
  }

  /* subtract */
  int max = 0;
  for (int h = 0; h < 100; h++) {
    for (int i = 0; i < blue; i++) {
      if (blue_str.at(h) == red_str.at(i)) {
        blue_count.at(h) -= red_count.at(i);
        break;
      }
    }
    if (max < blue_count.at(h)) {
      max = blue_count.at(h);
    }
  }
  cout << max << endl;

  // for (int i = 0; i < 100; i++) { cout << blue_count.at(i) << " " <<
  // red_count.at(i) << endl; } for (int i = 0; i < red + blue; i++) { cout <<
  // red_str.at(i) << blue_str.at(i) << endl; }
}
Problem p03408 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  s.at(N) = "{";
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());

  int c1 = 1, c2 = 0;
  for (int i = 1; i < N + 1; i++) {
    if (s.at(i - 1) == s.at(i)) {
      c1++;
    } else {
      for (int j = 0; j < M; j++) {
        if (t.at(j) == s.at(i - 1)) {
          c1--;
          cout << "t.at(i): " << t.at(i) << "c1: " << c1 << endl;
        }
      }
      c2 = max(c2, c1);
      c1 = 1;
    }
  }

  cout << c2 << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  s.at(N) = "{";
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());

  int c1 = 1, c2 = 0;
  for (int i = 1; i < N + 1; i++) {
    if (s.at(i - 1) == s.at(i)) {
      c1++;
    } else {
      for (int j = 0; j < M; j++) {
        if (t.at(j) == s.at(i - 1)) {
          c1--;
        }
      }
      c2 = max(c2, c1);
      c1 = 1;
    }
  }

  cout << c2 << endl;
}
Problem p03408 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < N; i++) {
    cin >> t.at(i);
  }
  int max = 0;
  int temp = 0;
  for (int i = 0; i < N; i++) {
    temp = 0;
    for (int j = 0; j < N; j++) {
      if (s.at(i) == s.at(j)) {
        temp++;
      }
    }
    for (int k = 0; k < M; k++) {
      if (s.at(i) == t.at(k)) {
        temp--;
      }
    }
    if (temp > max) {
      max = temp;
    }
  }
  cout << max << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  int max = 0;
  int temp = 0;
  for (int i = 0; i < N; i++) {
    temp = 0;
    for (int j = 0; j < N; j++) {
      if (s.at(i) == s.at(j)) {
        temp++;
      }
    }
    for (int k = 0; k < M; k++) {
      if (s.at(i) == t.at(k)) {
        temp--;
      }
    }
    if (temp > max) {
      max = temp;
    }
  }
  cout << max << endl;
}
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);
  for (int i = 0; i < n; i++)
    cin >> s[i];

  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++)
    cin >> t[i];

  vector<int> results(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (s[i] == s[j])
        results[i]++;

    for (int j = 0; j < n; j++)
      if (s[i] == t[j])
        results[i]--;
  }

  int rmax = 0;
  for (int i = 0; i < n; i++)
    rmax = max(rmax, results[i]);

  cout << rmax << endl;
}


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

int main() {
  int n, m;

  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];

  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++)
    cin >> t[i];

  vector<int> results(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (s[i] == s[j])
        results[i]++;

    for (int j = 0; j < m; j++)
      if (s[i] == t[j])
        results[i]--;
  }

  int rmax = 0;
  for (int i = 0; i < n; i++)
    rmax = max(rmax, results[i]);

  cout << rmax << endl;
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n;
  vector<string> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> m;
  vector<string> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int score = 0;
    for (int j = 0; j < n; j++)
      if (a[i] == a[j])
        score++;
    for (int j = 0; j < m; j++)
      if (b[i] == b[j])
        score--;
    ans = max(score, ans);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n;
  vector<string> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> m;
  vector<string> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int score = 0;
    for (int j = 0; j < n; j++)
      if (a[i] == a[j])
        score++;
    for (int j = 0; j < m; j++)
      if (a[i] == b[j])
        score--;
    ans = max(score, ans);
  }
  cout << ans << 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++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<string> blue_card(N);
  rep(i, N) { cin >> blue_card[i]; }
  int M;
  cin >> M;
  vector<string> red_card(M);
  rep(i, M) { cin >> red_card[i]; }
  int max_money = 0;
  rep(i, N) {
    int money = 1;
    for (int j = i + 1; j < N; j++) {
      if (blue_card[i] == blue_card[j]) {
        money++;
      }
    }
    rep(j, N) {
      if (blue_card[i] == red_card[j]) {
        money--;
      }
    }
    max_money = max(max_money, money);
  }
  cout << max_money << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<string> blue_card(N);
  rep(i, N) { cin >> blue_card[i]; }
  int M;
  cin >> M;
  vector<string> red_card(M);
  rep(i, M) { cin >> red_card[i]; }
  int max_money = 0;
  rep(i, N) {
    int money = 1;
    for (int j = i + 1; j < N; j++) {
      if (blue_card[i] == blue_card[j]) {
        money++;
      }
    }
    rep(j, M) {
      if (blue_card[i] == red_card[j]) {
        money--;
      }
    }
    max_money = max(max_money, money);
  }
  cout << max_money << endl;
}
Problem p03408 (C++)

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

using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n;
  vector<string> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> m;
  vector<string> T(m);
  for (int i = 0; i < m; i++) {
    cin >> T[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (S[i] == S[j]) {
        cnt++;
      }
    }
    for (int k = 0; k < n; k++) {
      if (S[i] == T[k]) {
        cnt--;
      }
    }
    ans = max(ans, cnt);
  }

  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n;
  vector<string> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> m;
  vector<string> T(m);
  for (int i = 0; i < m; i++) {
    cin >> T[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (S[i] == S[j]) {
        cnt++;
      }
    }
    for (int k = 0; k < m; k++) {
      if (S[i] == T[k]) {
        cnt--;
      }
    }
    ans = max(ans, cnt);
  }

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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> blue(n);
  for (int i = 0; i < n; ++i)
    cin >> blue[i];
  int m;
  cin >> m;
  vector<string> red(n);
  for (int i = 0; i < m; ++i)
    cin >> red[i];

  int ans = 0;
  auto calc = [&](string s) {
    int buf = 0;
    for (string t : blue) {
      if (t == s)
        buf++;
    }
    for (string t : red) {
      if (t == s)
        buf--;
    }
    return buf;
  };

  for (string t : blue) {
    ans = max(ans, calc(t));
  }

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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> blue(n);
  for (int i = 0; i < n; ++i)
    cin >> blue[i];
  int m;
  cin >> m;
  vector<string> red(m);
  for (int i = 0; i < m; ++i)
    cin >> red[i];

  int ans = 0;
  auto calc = [&](string s) {
    int buf = 0;
    for (string t : blue) {
      if (t == s)
        buf++;
    }
    for (string t : red) {
      if (t == s)
        buf--;
    }
    return buf;
  };

  for (string t : blue) {
    ans = max(ans, calc(t));
  }

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

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

using namespace std;

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

  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  int m;
  cin >> m;
  vector<string> t(n);
  for (int i = 0; i < m; i++) {
    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 (s[i] == t[j]) {
        score--;
      }
    }
    ans = max(ans, score);
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

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

  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  int m;
  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i++) {
    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 (s[i] == t[j]) {
        score--;
      }
    }
    ans = max(ans, score);
  }
  cout << ans << endl;

  return 0;
}
Problem p03408 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main(void) {
  int n, m;
  int count = 0;
  int point = 0;
  string p;

  cin >> n;
  vector<string> s(n);
  FOR(i, 0, n - 1) { cin >> s[i]; }
  cin >> m;
  vector<string> t(n);
  FOR(i, 0, n - 1) { cin >> t[i]; }

  FOR(i, 0, n - 1) {
    p = s[i];
    point = 0;
    FOR(u, 0, n - 1) {
      if (p == s[u]) {
        point++;
      }
    }
    FOR(u, 0, m - 1) {
      if (p == t[u]) {
        point--;
      }
    }
    if (point > count) {
      count = point;
    }
  }
  FOR(i, 0, m - 1) {
    p = t[i];
    point = 0;
    FOR(u, 0, n - 1) {
      if (p == s[u]) {
        point++;
      }
    }
    FOR(u, 0, m - 1) {
      if (p == t[u]) {
        point--;
      }
    }
    if (point > count) {
      count = point;
    }
  }

  cout << count << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main(void) {
  int n, m;
  int count = 0;
  int point = 0;
  string p;

  cin >> n;
  vector<string> s(n);
  FOR(i, 0, n - 1) { cin >> s[i]; }
  cin >> m;
  vector<string> t(m);
  FOR(i, 0, m - 1) { cin >> t[i]; }

  FOR(i, 0, n - 1) {
    p = s[i];
    point = 0;
    FOR(u, 0, n - 1) {
      if (p == s[u]) {
        point++;
      }
    }
    FOR(u, 0, m - 1) {
      if (p == t[u]) {
        point--;
      }
    }
    if (point > count) {
      count = point;
    }
  }
  FOR(i, 0, m - 1) {
    p = t[i];
    point = 0;
    FOR(u, 0, n - 1) {
      if (p == s[u]) {
        point++;
      }
    }
    FOR(u, 0, m - 1) {
      if (p == t[u]) {
        point--;
      }
    }
    if (point > count) {
      count = point;
    }
  }

  cout << count << endl;
  return 0;
}