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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define For(i, a, b) for (int i = a, i##E = b; i <= i##E; ++i)
#define rFor(i, a, b) for (int i = a, i##E = b; i >= i##E; --i)
typedef long long LL;
using namespace std;
template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline void read(T &x) {
  x = 0;
  int _f(0);
  char ch = getchar();
  while (!isdigit(ch))
    _f |= (ch == '-'), ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = _f ? -x : x;
}
inline void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
map<int, int> mp;
int n, m;
int main() {
  file();
  int x;
  read(n);
  For(i, 1, n) read(x), mp[x]++;
  read(m);
  For(i, 1, m) {
    read(x);
    if (!mp[x]) {
      puts("NO");
      return 0;
    }
    mp[x]--;
  }
  puts("YES");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define For(i, a, b) for (int i = a, i##E = b; i <= i##E; ++i)
#define rFor(i, a, b) for (int i = a, i##E = b; i >= i##E; --i)
typedef long long LL;
using namespace std;
template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline void read(T &x) {
  x = 0;
  int _f(0);
  char ch = getchar();
  while (!isdigit(ch))
    _f |= (ch == '-'), ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = _f ? -x : x;
}
inline void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}
map<int, int> mp;
int n, m;
int main() {
  // file();
  int x;
  read(n);
  For(i, 1, n) read(x), mp[x]++;
  read(m);
  For(i, 1, m) {
    read(x);
    if (!mp[x]) {
      puts("NO");
      return 0;
    }
    mp[x]--;
  }
  puts("YES");
  return 0;
}
Problem p03578 (C++)

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

using namespace std;

const int MAXN = 100 * 1000 + 10;
const int MAXM = 100 * 1000 + 10;

int a[MAXN], b[MAXM];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++)
    cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  int i = 0;
  while (i < m) {
    int j = i;
    while (i < m && b[i] == b[j])
      i++;
    int have = upper_bound(a, a + n, b[j]) - lower_bound(a, a + n, b[j]);
    if (have < i - j) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

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

using namespace std;

const int MAXN = 200 * 1000 + 10;
const int MAXM = 200 * 1000 + 10;

int a[MAXN], b[MAXM];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++)
    cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  int i = 0;
  while (i < m) {
    int j = i;
    while (i < m && b[i] == b[j])
      i++;
    int have = upper_bound(a, a + n, b[j]) - lower_bound(a, a + n, b[j]);
    if (have < i - j) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
map<int, int> mp;
#define maxn 110
int a[maxn];
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++mp[x];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i)
    scanf("%d", &a[i]);
  for (int i = 0; i < m; ++i) {
    if (mp.find(a[i]) == mp.end()) {
      printf("NO\n");
      return 0;
    }
    --mp[a[i]];
    if (mp[a[i]] == 0)
      mp.erase(a[i]);
  }
  printf("YES\n");

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
map<int, int> mp;
#define maxn 200010
int a[maxn];
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++mp[x];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i)
    scanf("%d", &a[i]);
  for (int i = 0; i < m; ++i) {
    if (mp.find(a[i]) == mp.end()) {
      printf("NO\n");
      return 0;
    }
    --mp[a[i]];
    if (mp[a[i]] == 0)
      mp.erase(a[i]);
  }
  printf("YES\n");

  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
struct bt {
  int n;
  int l;
  int r;
  int left;
};
bt b[20];
int now = 0;
void insert(int n, int here) {
  if (now == 0) {
    b[0].n = n;
    b[0].l = 0;
    b[0].r = 0;
    b[0].left = 1;
    now++;
    return;
  }
  if (n == b[here].n) {
    b[here].left++;
    return;
  }
  if (n > b[here].n) {
    if (b[here].r == 0) {
      b[here].r = now;
      b[now].n = n;
      b[now].l = 0;
      b[now].r = 0;
      b[now].left = 1;
      now++;
      return;
    } else {
      insert(n, b[here].r);
      return;
    }
  }
  if (b[here].l == 0) {
    b[here].l = now;
    b[now].n = n;
    b[now].l = 0;
    b[now].r = 0;
    b[now].left = 1;
    now++;
    return;
  }
  insert(n, b[here].l);
  return;
}
bool find(int n, int here) {
  if (b[here].n == n) {
    if (b[here].left > 0) {
      b[here].left--;
      return true;
    }
    return false;
  }
  if (b[here].n > n) {
    if (b[here].l == 0)
      return false;
    return find(n, b[here].l);
  }
  if (b[here].r == 0)
    return false;
  return find(n, b[here].r);
}
int main() {
  int n, temp, m;
  bool f;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &temp);
    insert(temp, 0);
  }
  scanf("%d", &m);
  f = m <= n;
  for (int i = 0; i < m && f; i++) {
    scanf("%d", &temp);
    f = find(temp, 0);
  }
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

Fixed submission:
#include <stdio.h>
struct bt {
  int n;
  int l;
  int r;
  int left;
};
bt b[1000000];
int now = 0;
void insert(int n, int here) {
  if (now == 0) {
    b[0].n = n;
    b[0].l = 0;
    b[0].r = 0;
    b[0].left = 1;
    now++;
    return;
  }
  if (n == b[here].n) {
    b[here].left++;
    return;
  }
  if (n > b[here].n) {
    if (b[here].r == 0) {
      b[here].r = now;
      b[now].n = n;
      b[now].l = 0;
      b[now].r = 0;
      b[now].left = 1;
      now++;
      return;
    } else {
      insert(n, b[here].r);
      return;
    }
  }
  if (b[here].l == 0) {
    b[here].l = now;
    b[now].n = n;
    b[now].l = 0;
    b[now].r = 0;
    b[now].left = 1;
    now++;
    return;
  }
  insert(n, b[here].l);
  return;
}
bool find(int n, int here) {
  if (b[here].n == n) {
    if (b[here].left > 0) {
      b[here].left--;
      return true;
    }
    return false;
  }
  if (b[here].n > n) {
    if (b[here].l == 0)
      return false;
    return find(n, b[here].l);
  }
  if (b[here].r == 0)
    return false;
  return find(n, b[here].r);
}
int main() {
  int n, temp, m;
  bool f;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &temp);
    insert(temp, 0);
  }
  scanf("%d", &m);
  f = m <= n;
  for (int i = 0; i < m && f; i++) {
    scanf("%d", &temp);
    f = find(temp, 0);
  }
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ll long long
#define INF 1000000001
using namespace std;
struct Edge {
  int from, to, cost;
};

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

  int n;
  cin >> n;
  int a[100001];
  int b[100001];
  map<int, int> mp;

  REP(i, n) {
    cin >> a[i];
    if (mp[a[i]] == 0)
      mp[a[i]] = 1;
    else if (mp[a[i]] > 0)
      mp[a[i]]++;
  }

  int m;
  cin >> m;

  REP(i, m) {
    cin >> b[i];
    mp[b[i]]--;
  }
  int flag = 0;
  REP(i, m) {
    if (mp[b[i]] < 0) {
      flag = 1;
      break;
    }
  }

  if (flag == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}

Fixed submission:
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ll long long
#define INF 1000000001
using namespace std;
struct Edge {
  int from, to, cost;
};

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

  int n;
  cin >> n;
  int a[200001];
  int b[200001];
  map<int, int> mp;

  REP(i, n) {
    cin >> a[i];
    if (mp[a[i]] == 0)
      mp[a[i]] = 1;
    else if (mp[a[i]] > 0)
      mp[a[i]]++;
  }

  int m;
  cin >> m;

  REP(i, m) {
    cin >> b[i];
    mp[b[i]]--;
  }
  int flag = 0;
  REP(i, m) {
    if (mp[b[i]] < 0) {
      flag = 1;
      break;
    }
  }

  if (flag == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
Problem p03578 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  int a[200005], s[200005];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i];
  }
  sort(a, a + n);
  sort(s, s + m);
  int x = 0;
  for (int i = 0, j = 0; i < n && j < m;) {
    if (a[i] == s[j]) {
      i++;
      j++;
      x++;
    } else if (a[i] > s[j])
      j++;
  }
  if (x == m)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  int a[200005], s[200005];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i];
  }
  sort(a, a + n);
  sort(s, s + m);
  int x = 0;
  for (int i = 0, j = 0; i < n && j < m;) {
    if (a[i] == s[j]) {
      i++;
      j++;
      x++;
    } else if (a[i] > s[j])
      j++;
    else
      i++;
  }
  if (x == m)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
Problem p03578 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d[i];
  int m;
  cin >> m;
  vector<int> t(m);
  for (int i = 0; i < m; i++)
    cin >> t[i];
  sort(d.begin(), d.end());
  sort(t.begin(), t.end());
  int j = 0;
  bool can = true;
  for (int i = 0; i < m; i++) {
    if (j == n)
      continue;
    while (d[j] != t[i]) {
      j++;
      if (j == n) {
        can = false;
        break;
      }
    }
    j++;
  }
  cout << (can ? "YES" : "NO") << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d[i];
  int m;
  cin >> m;
  vector<int> t(m);
  for (int i = 0; i < m; i++)
    cin >> t[i];
  sort(d.begin(), d.end());
  sort(t.begin(), t.end());
  int j = 0;
  bool can = true;
  for (int i = 0; i < m; i++) {
    if (j >= n)
      continue;
    while (d[j] != t[i]) {
      j++;
      if (j == n) {
        can = false;
        break;
      }
    }
    j++;
  }
  cout << (can ? "YES" : "NO") << endl;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
constexpr int MOD = 1000000007;
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\n"
#define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 2e5 + 5;

int main(void) {
  int N;
  cin >> N;
  int D[N];
  rep(i, N) cin >> D[i];
  sort(D, D + N);
  int M;
  cin >> M;
  int T[M];
  rep(i, M) cin >> T[i];
  sort(T, T + M);
  bool ans = true;
  int now = -1;
  rep(i, M) {
    now++;
    while (T[i] != D[now] && now < N)
      now++;
    if (now == N)
      ans = false;
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
constexpr int MOD = 1000000007;
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\n"
#define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int MAX_N = 2e5 + 5;

int main(void) {
  int N;
  cin >> N;
  int D[N];
  rep(i, N) cin >> D[i];
  sort(D, D + N);
  int M;
  cin >> M;
  int T[M];
  rep(i, M) cin >> T[i];
  sort(T, T + M);
  bool ans = true;
  int now = -1;
  rep(i, M) {
    now++;
    while (T[i] != D[now] && now < N)
      now++;
    if (now == N)
      ans = false;
    if (!ans)
      break;
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03578 (C++)

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

int main() {
  int i, j;
  int m, n;
  int a[100010], b[100010];
  map<int, int> mpa, mpb;
  scanf("%d", &m);
  rep(i, 0, m) { scanf("%d", &a[i]); }
  scanf("%d", &n);
  rep(j, 0, n) { scanf("%d", &b[j]); }
  rep(i, 0, m) { mpa[a[i]]++; }
  rep(j, 0, n) { mpb[b[j]]++; }
  rep(i, 0, n) {
    int x = b[i];
    if (mpb[x] > mpa[x]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}


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

int main() {
  int i, j;
  int m, n;
  int a[200010], b[200010];
  map<int, int> mpa, mpb;
  scanf("%d", &m);
  rep(i, 0, m) { scanf("%d", &a[i]); }
  scanf("%d", &n);
  rep(j, 0, n) { scanf("%d", &b[j]); }
  rep(i, 0, m) { mpa[a[i]]++; }
  rep(j, 0, n) { mpb[b[j]]++; }
  rep(i, 0, n) {
    int x = b[i];
    if (mpb[x] > mpa[x]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
using namespace std;
int a[500000];
int b[500000];
int main() {
  int n, l, sign, i, m;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  scanf("%d", &m);
  for (i = 1; i <= m; i++)
    scanf("%d", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  l = 1;
  sign = 0;
  for (i = 1; i <= m; i++) {
    if (a[l] == b[i]) {
      l++;
      continue;
    }
    while (a[l] < b[i])
      l++;
    if (a[l] == b[i]) {
      l++;
      continue;
    }
    if (a[l] > b[i])
      sign = 1;
  }
  if (sign == 0)
    printf("YES\n");
  else
    printf("NO\n");
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
using namespace std;
int a[500000];
int b[500000];
int main() {
  int n, l, sign, i, m;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  scanf("%d", &m);
  for (i = 1; i <= m; i++)
    scanf("%d", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  l = 1;
  sign = 0;
  for (i = 1; i <= m; i++) {
    if (a[l] == b[i]) {
      l++;
      continue;
    }
    while (a[l] < b[i] && l <= n)
      l++;
    if (a[l] == b[i]) {
      l++;
      continue;
    }
    if (a[l] > b[i])
      sign = 1;
  }
  if (sign == 0)
    printf("YES\n");
  else
    printf("NO\n");
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair<ll, ll> P;

int main() {
  string S;
  cin >> S;
  S.erase(S.size() - 8, 8);
  print(S);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair<ll, ll> P;

int main() {
  ll N;
  cin >> N;
  map<ll, ll> mp;
  rep(i, N) {
    ll D;
    cin >> D;
    mp[D]++;
  }
  ll M;
  cin >> M;
  rep(i, M) {
    ll T;
    cin >> T;
    if (mp[T] > 0) {
      mp[T]--;
    } else {
      NO;
      return 0;
    }
  }
  YES;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <deque>   // deque
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define mod 1000000007
vector<ll> to[1000005];
ll dp[2000000];
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  vector<ll> a(100000000, 0);
  ll b, c;
  cin >> b;
  rep(i, b) {
    cin >> c;
    a[c]++;
  }
  cin >> b;
  vector<ll> d(b, 0);
  rep(i, b) { cin >> d[i]; }
  rep(i, b) {
    if (a[d[i]] == 0) {
      cout << "NO";
      return 0;
    }
    a[d[i]]--;
  }
  cout << "YES";
}


Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <climits>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <deque>   // deque
#include <functional>
#include <iomanip> //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define mod 1000000007
vector<ll> to[1000005];
ll dp[2000000];
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  map<ll, ll> a;
  ll b, c;
  cin >> b;
  rep(i, b) {
    cin >> c;
    a[c]++;
  }
  cin >> b;
  vector<ll> d(b, 0);
  rep(i, b) { cin >> d[i]; }
  rep(i, b) {
    if (a[d[i]] == 0) {
      cout << "NO";
      return 0;
    }
    a[d[i]]--;
  }
  cout << "YES";
}
Problem p03578 (C++)

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

#define PI 4 * atan(1)
#define INF 1e8

typedef long long ll;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  map<int, int> cnt;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    cnt[D[i] - 1]++;
  }
  int M;
  cin >> M;
  vector<int> T(M);
  bool flag = true;
  for (int i = 0; i < M; i++) {
    cin >> T[i];
    if (D[T[i] - 1]) {
      D[T[i] - 1]--;
    } else {
      flag = false;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

#define PI 4 * atan(1)
#define INF 1e8

typedef long long ll;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  map<int, int> cnt;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    cnt[D[i] - 1]++;
  }
  int M;
  cin >> M;
  vector<int> T(M);
  bool flag = true;
  for (int i = 0; i < M; i++) {
    cin >> T[i];
    if (cnt[T[i] - 1]) {
      cnt[T[i] - 1]--;
    } else {
      flag = false;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main() {
  int A, B;
  int a[100010] = {0};
  int b[100010] = {0};
  map<int, int> mpa, mpb; // D, T
  cin >> A;
  rep(i, A) cin >> a[i];
  cin >> B;
  rep(i, B) cin >> b[i];
  rep(i, A) mpa[a[i]]++;
  rep(i, B) mpb[b[i]]++;
  rep(i, B) {
    int x = b[i];
    if (mpb[x] > mpa[x]) { // T > D
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main() {
  int A, B;
  int a[200010] = {0};
  int b[200010] = {0};
  map<int, int> mpa, mpb; // D, T
  cin >> A;
  rep(i, A) cin >> a[i];
  cin >> B;
  rep(i, B) cin >> b[i];
  rep(i, A) mpa[a[i]]++;
  rep(i, B) mpb[b[i]]++;
  rep(i, B) {
    int x = b[i];
    if (mpb[x] > mpa[x]) { // T > D
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;
using ll = double;
map<int, int> mpa, mpb;

int main(void) {
  int N;
  int a;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    mpa[a]++;
  }
  int M;
  int b;
  int B[100000007];
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> b;
    B[i] = b;
    mpb[b]++;
  }
  int x;
  for (int i = 0; i < M; i++) {
    x = B[i];
    if (mpa[x] < mpb[x]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <stdio.h>
#include <vector>
using namespace std;
using ll = double;
map<int, int> mpa, mpb;

int main(void) {
  int N;
  int a;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    mpa[a]++;
  }
  int M;
  int b;
  int B[10000007];
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> b;
    B[i] = b;
    mpb[b]++;
  }
  int x;
  for (int i = 0; i < M; i++) {
    x = B[i];
    if (mpa[x] < mpb[x]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
Problem p03578 (C++)

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

int main() {
  int N, M;
  cin >> N;
  vector<int> count(200000 + 100);
  rep(i, N) {
    int d;
    cin >> d;
    count[d]++;
  }
  cin >> M;
  string ans = "YES";
  rep(i, M) {
    int t;
    cin >> t;
    if (count[t] <= 0) {
      ans = "NO";
      break;
    }
    count[t]--;
  }
  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;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N;
  map<int, int> count;
  rep(i, N) {
    int d;
    cin >> d;
    count[d]++;
  }
  cin >> M;
  string ans = "YES";
  rep(i, M) {
    int t;
    cin >> t;
    if (count[t] <= 0) {
      ans = "NO";
      break;
    }
    count[t]--;
  }
  cout << ans << endl;
  return 0;
}
Problem p03578 (C++)

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

int d[200005] = {0};

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    d[a]++;
  }
  int m;
  cin >> m;
  bool flag = true;
  for (int i = 0; i < m; ++i) {
    int t;
    cin >> t;
    if (flag) {
      d[t]--;
      if (d[t] < 0)
        flag = false;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

map<int, int> d;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    d[a]++;
  }
  int m;
  cin >> m;
  bool flag = true;
  for (int i = 0; i < m; ++i) {
    int t;
    cin >> t;
    if (flag) {
      d[t]--;
      if (d[t] < 0)
        flag = false;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int N, M, a[100009], b[100009];
map<int, int> d;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> a[i], d[a[i]]++;
  cin >> M;
  for (int i = 0; i < M; i++)
    cin >> b[i];
  bool f = true;
  for (int i = 0; i < M; i++) {
    if (!d[b[i]])
      f = false;
    else
      d[b[i]]--;
  }
  cout << (f ? "YES" : "NO") << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int N, M, a[200009], b[200009];
map<int, int> d;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> a[i], d[a[i]]++;
  cin >> M;
  for (int i = 0; i < M; i++)
    cin >> b[i];
  bool f = true;
  for (int i = 0; i < M; i++) {
    if (!d[b[i]])
      f = false;
    else
      d[b[i]]--;
  }
  cout << (f ? "YES" : "NO") << endl;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, i, j = -1;
  bool ans = true;
  cin >> n;
  int d[n + 1];
  d[n] = 1000000001;
  for (i = 0; i < n; i++)
    cin >> d[i];
  cin >> m;
  int t[m];
  for (i = 0; i < m; i++)
    cin >> t[i];
  sort(d, d + n);
  sort(t, t + m);
  for (i = 0; i < m; i++) {
    j += 1;
    while (d[j] != t[i]) {
      if (j == n || d[j] > t[i]) {
        ans = false;
        break;
      }
      j += 1;
    }
  }
  cout << ((ans) ? "YES" : "NO") << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, i, j = -1;
  bool ans = true;
  cin >> n;
  int d[n + 1];
  d[n] = 1000000001;
  for (i = 0; i < n; i++)
    cin >> d[i];
  cin >> m;
  int t[m];
  for (i = 0; i < m; i++)
    cin >> t[i];
  sort(d, d + n);
  sort(t, t + m);
  for (i = 0; i < m; i++) {
    j += 1;
    while (d[j] != t[i]) {
      if (j == n || d[j] > t[i]) {
        ans = false;
        break;
      }
      j += 1;
    }
    if (ans == false)
      break;
  }
  cout << ((ans) ? "YES" : "NO") << endl;
}
Problem p03578 (C++)

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

int main() {
  int N, M, cnt = 0, ans = 0;
  cin >> N;
  ll D[N];
  for (int i = 0; i < N; i++)
    cin >> D[i];
  cin >> M;
  ll T[M];
  for (int i = 0; i < M; i++)
    cin >> T[i];

  map<int, int> mpa, mpb;
  for (int i = 0; i < N; i++)
    mpa[D[i]]++;
  for (int i = 0; i < M; i++)
    mpb[T[i]]++;
  for (int i = 0; i < M; i++) {
    int x = T[i];
    if (D[x] < T[x]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

int main() {
  int N, M, cnt = 0, ans = 0;
  cin >> N;
  ll D[N];
  for (int i = 0; i < N; i++)
    cin >> D[i];
  cin >> M;
  ll T[M];
  for (int i = 0; i < M; i++)
    cin >> T[i];

  map<int, int> mpa, mpb;
  for (int i = 0; i < N; i++)
    mpa[D[i]]++;
  for (int i = 0; i < M; i++)
    mpb[T[i]]++;
  for (int i = 0; i < M; i++) {
    int x = T[i];
    if (mpa[x] < mpb[x]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <cstdio>
#define ll long long

const int N = 1e8 + 7;
int b[N];
int n, t;

int main() {
  ll x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x);
    b[x % N]++;
  }
  scanf("%d", &t);
  if (t > n) {
    printf("NO");
    return 0;
  }
  for (int i = 1; i <= t; i++) {
    scanf("%lld", &x);
    x = x % N;
    b[x]--;
    if (b[x] < 0) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}

Fixed submission:
#include <cstdio>
#define ll long long

const int N = 1e7 + 7;
int b[N];
int n, t;

int main() {
  ll x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x);
    b[x % N]++;
  }
  scanf("%d", &t);
  if (t > n) {
    printf("NO");
    return 0;
  }
  for (int i = 1; i <= t; i++) {
    scanf("%lld", &x);
    x = x % N;
    b[x]--;
    if (b[x] < 0) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}
Problem p03578 (C++)

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

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];

  int m;
  cin >> m;
  vector<int> t(n);
  rep(i, m) cin >> t[i];

  sort(d.begin(), d.end());
  sort(t.begin(), t.end());

  int j = 0;
  rep(i, m) {

    while (1) {

      if (t[i] == d[j++]) {
        break;
      }
      if (j >= n) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];

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

  sort(d.begin(), d.end());
  sort(t.begin(), t.end());

  int j = 0;
  rep(i, m) {

    while (1) {

      if (t[i] == d[j++]) {
        break;
      }
      if (j >= n) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
Problem p03578 (C++)

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  ll n, m;
  cin >> n;
  vector<ll> num(n);
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;
    num[x]++;
  }
  cin >> m;
  for (ll i = 0; i < m; i++) {
    ll x;
    cin >> x;
    num[x]--;
    if (num[x] < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  ll n, m;
  cin >> n;
  map<int, int> num;
  for (ll i = 0; i < n; i++) {
    ll x;
    cin >> x;
    num[x]++;
  }
  cin >> m;
  for (ll i = 0; i < m; i++) {
    ll x;
    cin >> x;
    num[x]--;
    if (num[x] < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <map>
#include <stdio.h>
using namespace std;
int main() {
  int m, n, d, t;
  map<int, int> dd, tt;
  map<int, int>::iterator it, id;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d);
    dd[d]++;
  }
  int count = 0;
  scanf("%d", &m);
  if (m > n) {
    printf("NO\n");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &t);
    tt[t]++;
  }
  for (it = tt.begin(), id = dd.begin(); it != tt.end(); it++, id++) {
    if (it->first > id->first) {
      while (it != id) {
        it++;
      }
    } else if (it->first < id->first) {
      while (it != id) {
        id++;
      }
    } else {
      if (it->second > id->second) {
        printf("NO\n");
        return 0;
      }
    }
  }
  printf("YES\n");
  return 0;
}

Fixed submission:
#include <map>
#include <stdio.h>
using namespace std;
int main() {
  int m, n, d, t;
  map<int, int> dd, tt;
  map<int, int>::iterator it, id;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d);
    dd[d]++;
  }
  int count = 0;
  scanf("%d", &m);
  if (m > n) {
    printf("NO\n");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &t);
    tt[t]++;
  }
  for (it = tt.begin(); it != tt.end(); it++) {
    if (it->second > dd[it->first]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;
string s;

LL D[100000], T[1000000];
int main() {
  LL n;
  scanf("%lld", &n);
  for (LL i = 0; i < n; ++i)
    scanf("%lld", D + i);
  LL m;
  scanf("%lld", &m);
  for (LL i = 0; i < m; ++i)
    scanf("%lld", T + i);
  sort(D, D + n);
  sort(T, T + m);
  LL j = 0;
  for (LL i = 0; i < n; ++i) {
    if (D[i] == T[j])
      ++j;
  }
  puts(j == m ? "YES" : "NO");
}


Fixed submission:
#ifdef __APPLE__
#include "bits:stdc++.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;
string s;

LL D[1000000], T[1000000];
int main() {
  LL n;
  scanf("%lld", &n);
  for (LL i = 0; i < n; ++i)
    scanf("%lld", D + i);
  LL m;
  scanf("%lld", &m);
  for (LL i = 0; i < m; ++i)
    scanf("%lld", T + i);
  sort(D, D + n);
  sort(T, T + m);
  LL j = 0;
  for (LL i = 0; i < n; ++i) {
    if (D[i] == T[j])
      ++j;
  }
  puts(j == m ? "YES" : "NO");
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr << "[" << (x).FI << ", " << (x).SE << "]";
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWVEC(v, e)                                                          \
  REP(i, e) cerr << (v[i]) << ' ';                                             \
  cerr << endl;
#define SHOW2D(a, h, w)                                                        \
  REP(i, h) {                                                                  \
    REP(j, w) cerr << setw(3) << (a[i][j]) << ' ';                             \
    cerr << endl;                                                              \
  }
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  REP(i, N) cin >> D[i];

  int M;
  cin >> M;
  vector<int> T(N);
  REP(i, M) cin >> T[i];

  map<int, int> mp;
  REP(i, N) mp[D[i]]++;
  REP(i, M) {
    if (mp[T[i]] <= 0) {
      cout << "NO" << endl;
      return 0;
    }
    mp[T[i]]--;
  }
  cout << "YES" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr << "[" << (x).FI << ", " << (x).SE << "]";
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWVEC(v, e)                                                          \
  REP(i, e) cerr << (v[i]) << ' ';                                             \
  cerr << endl;
#define SHOW2D(a, h, w)                                                        \
  REP(i, h) {                                                                  \
    REP(j, w) cerr << setw(3) << (a[i][j]) << ' ';                             \
    cerr << endl;                                                              \
  }
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  REP(i, N) cin >> D[i];

  int M;
  cin >> M;
  vector<int> T(M);
  REP(i, M) cin >> T[i];

  map<int, int> mp;
  REP(i, N) mp[D[i]]++;
  REP(i, M) {
    if (mp[T[i]] <= 0) {
      cout << "NO" << endl;
      return 0;
    }
    mp[T[i]]--;
  }
  cout << "YES" << endl;

  return 0;
}
Problem p03578 (C++)

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

int main() {
  int n, m;
  cin >> n;
  vector<long int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  cin >> m;
  vector<long int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int i = 0;
  int j = 0;
  int count = 0;
  while (i < n | j < m) {
    if (i == n - 1) {
      if (a.at(i) == b.at(j)) {
        count++;
        break;
      } else {
        j++;
        continue;
      }
    }
    if (j == m - 1) {
      if (a.at(i) == b.at(j)) {
        count++;
        break;
      } else {
        i++;
        continue;
      }
    }
    if (a.at(i) == b.at(j)) {
      count++;
      i++;
      j++;
    } else if (a.at(i) < b.at(j)) {
      i++;
    } else {
      j++;
    }
  }
  if (n == 1 & m == 1) {
    if (a.at(0) == b.at(0)) {
      count++;
    }
  }
  if (count == m) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}

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

int main() {
  int n, m;
  cin >> n;
  vector<long int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  cin >> m;
  vector<long int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int i = 0;
  int j = 0;
  int count = 0;
  while (i < n & j < m) {
    if (i == n - 1) {
      if (a.at(i) == b.at(j)) {
        count++;
        break;
      } else {
        j++;
        continue;
      }
    }
    if (j == m - 1) {
      if (a.at(i) == b.at(j)) {
        count++;
        break;
      } else {
        i++;
        continue;
      }
    }
    if (a.at(i) == b.at(j)) {
      count++;
      i++;
      j++;
    } else if (a.at(i) < b.at(j)) {
      i++;
    } else {
      j++;
    }
  }
  if (n == 1 & m == 1) {
    if (a.at(0) == b.at(0)) {
      count++;
    }
  }
  if (count == m) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}
Problem p03578 (C++)

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

int main() {
  int N, M;
  cin >> N;
  multiset<int> D;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    D.insert(x);
  }
  cin >> M;
  vector<int> T(N);
  for (int i = 0; i < M; ++i)
    cin >> T[i];

  for (int i = 0; i < M; ++i) {
    auto it = D.find(T[i]);
    if (it == D.end()) {
      cout << "NO" << endl;
      return 0;
    }
    D.erase(it);
  }

  cout << "YES" << endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N;
  multiset<int> D;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    D.insert(x);
  }
  cin >> M;
  vector<int> T(M);
  for (int i = 0; i < M; ++i)
    cin >> T[i];

  for (int i = 0; i < M; ++i) {
    auto it = D.find(T[i]);
    if (it == D.end()) {
      cout << "NO" << endl;
      return 0;
    }
    D.erase(it);
  }

  cout << "YES" << endl;
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
inline void readLong(ll &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
/*================Header Template==============*/
multiset<int> s;
int n, x;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    s.insert(x);
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    multiset<int>::iterator it = find(s.begin(), s.end(), x);
    if (it == s.end()) {
      puts("NO");
      return 0;
    }
    s.erase(it);
  }
  puts("YES");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
inline void readLong(ll &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
/*================Header Template==============*/
multiset<int> s;
int n, x;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    s.insert(x);
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    multiset<int>::iterator it = s.find(x);
    if (it == s.end()) {
      puts("NO");
      return 0;
    }
    s.erase(it);
  }
  puts("YES");
  return 0;
}
Problem p03578 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100005
int n, m;
int a[N], b[N];
int main() {
  scanf("%d", &n);
  map<int, int> cnt;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), cnt[a[i]]++;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    if (cnt[b[i]] == 0) {
      printf("NO\n");
      return 0;
    }
    cnt[b[i]]--;
  }
  printf("YES\n");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200005
int n, m;
int a[N], b[N];
int main() {
  scanf("%d", &n);
  map<int, int> cnt;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), cnt[a[i]]++;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    if (cnt[b[i]] == 0) {
      printf("NO\n");
      return 0;
    }
    cnt[b[i]]--;
  }
  printf("YES\n");
  return 0;
}
Problem p03578 (C++)

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

int N, M;
int A[100010], B[100010];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", A + i);
  scanf("%d", &M);
  for (int i = 0; i < M; i++)
    scanf("%d", B + i);

  sort(A, A + N);
  sort(B, B + M);

  int l = 0;

  for (int i = 0; i < M; i++) {
    while (l < N && B[i] != A[l])
      l++;
    l++;
    if (l > N) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}


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

int N, M;
int A[200010], B[200010];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", A + i);
  scanf("%d", &M);
  for (int i = 0; i < M; i++)
    scanf("%d", B + i);

  sort(A, A + N);
  sort(B, B + M);

  int l = 0;

  for (int i = 0; i < M; i++) {
    while (l < N && B[i] != A[l])
      l++;
    l++;
    if (l > N) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}