alexjercan/bugnet huggingface dataset:
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

vector<int> ch(string s) {
  vector<int> r;
  rep(i, s.size()) r.push_back(s[i] - 'A');
  return r;
}

string hc(vector<int> v) {
  string s = "";
  rep(i, v.size()) s += (char)(v[i] + 'A');
  return s;
}

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;

  int d[] = {a, b, c}, m = a + b + c;

  vector<string> vs(n);
  rep(i, n) cin >> vs[i];

  bool f = true;
  vector<int> ans;
  rep(i, n) {
    auto v = ch(vs[i]);

    if (d[v[0]] == 0 && d[v[1]] == 0) {
      f = false;
      break;
    }

    if (m == 2 && i != n - 1 && d[v[0]] == 1 && d[v[1]] == 1) {
      auto nv = ch(vs[i + 1]);
      if (v != nv) {
        if (v[0] == nv[0] || v[0] == nv[1]) {
          d[v[0]]++;
          d[v[1]]--;
          ans.push_back(v[0]);
        } else {
          d[v[0]]--;
          d[v[1]]++;
          ans.push_back(v[1]);
        }
        continue;
      }
    }

    if (d[v[0]] > d[v[1]]) {
      d[v[0]]--;
      d[v[1]]++;
      ans.push_back(v[1]);
    } else {
      d[v[0]]++;
      d[v[1]]--;
      ans.push_back(v[0]);
    }
  }

  if (f) {
    cout << "Yes" << endl;
    rep(i, n) cout << char(ans[i] + 'A') << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}

template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

pair<int, int> ch(string s) {
  if (s == "AB")
    return {0, 1};
  if (s == "BC")
    return {1, 2};
  if (s == "AC")
    return {0, 2};
}

string hc(pair<int, int> p) {
  int x = p.first, y = p.second;
  if (x == 0 && y == 1)
    return "AB";
  if (x == 1 && y == 2)
    return "BC";
  else
    return "AC";
}

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;

  vector<string> vs(n);
  rep(i, n) cin >> vs[i];

  int d[] = {a, b, c};

  int m = a + b + c;
  assert(m != 2);

  bool f = true;
  vector<string> ans(n);
  rep(i, n) {
    auto p = ch(vs[i]);
    if (d[p.first] == 0 && d[p.second] == 0) {
      f = false;
      break;
    }

    if (d[p.first] > d[p.second]) {
      d[p.first]--;
      d[p.second]++;
      ans[i] = hc(p)[1];
    } else {
      d[p.first]++;
      d[p.second]--;
      ans[i] = hc(p)[0];
    }
  }

  if (f) {
    cout << "Yes" << endl;
    rep(i, n) cout << ans[i] << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>

int main() {
  int N, A[3], i, j, k, nj, nk;
  char s[3];
  int ans[100000];
  scanf("%d%d%d%d", &N, A, A + 1, A + 2);
  // if(A[0] + A[1] + A[2] == 0){
  //   printf("No");
  // }
  scanf("%s", s);
  if (strcmp(s, "AB") == 0) {
    j = 0;
    k = 1;
  }
  if (strcmp(s, "AC") == 0) {
    j = 0;
    k = 2;
  }
  if (strcmp(s, "BC") == 0) {
    j = 1;
    k = 2;
  }
  for (i = 0; i < N; i++) {
    if (i != N - 1) {
      scanf("%s", s);
      if (strcmp(s, "AB") == 0) {
        nj = 0;
        nk = 1;
      }
      if (strcmp(s, "AC") == 0) {
        nj = 0;
        nk = 2;
      }
      if (strcmp(s, "BC") == 0) {
        nj = 1;
        nk = 2;
      }
    }
    if (A[j] == 0 && A[k] == 0) {
      printf("No");
      // break;
      return 0;
    }
    if (A[j] == 0) {
      A[j]++;
      A[k]--;
      ans[i] = j;
    } else if (A[k] == 0) {
      A[j]--;
      A[k]++;
      ans[i] = k;
    } else if (i != N - 1) {
      if (j == nj || j == nk) {
        A[j]++;
        A[k]--;
        ans[i] = j;
      } else {
        A[j]--;
        A[k]++;
        ans[i] = k;
      }
    } else {
      A[j]++;
      A[k]--;
      ans[i] = j;
    }
    j = nj;
    k = nk;
  }
  printf("Yes\\n");
  for (i = 0; i < N; i++) {
    printf("%c\\n", 'A' + ans[i]);
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  int N, A[3], i, j, k, nj, nk;
  char s[3];
  int ans[10000];
  scanf("%d%d%d%d", &N, A, A + 1, A + 2);
  // if(A[0] + A[1] + A[2] == 0){
  //   printf("No");
  // }
  scanf("%s", s);
  if (strcmp(s, "AB") == 0) {
    j = 0;
    k = 1;
  }
  if (strcmp(s, "AC") == 0) {
    j = 0;
    k = 2;
  }
  if (strcmp(s, "BC") == 0) {
    j = 1;
    k = 2;
  }
  for (i = 0; i < N; i++) {
    if (i != N - 1) {
      scanf("%s", s);
      if (strcmp(s, "AB") == 0) {
        nj = 0;
        nk = 1;
      }
      if (strcmp(s, "AC") == 0) {
        nj = 0;
        nk = 2;
      }
      if (strcmp(s, "BC") == 0) {
        nj = 1;
        nk = 2;
      }
    }
    if (A[j] == 0 && A[k] == 0) {
      printf("No");
      // break;
      return 0;
    }
    if (A[j] == 0) {
      A[j]++;
      A[k]--;
      ans[i] = j;
    } else if (A[k] == 0) {
      A[j]--;
      A[k]++;
      ans[i] = k;
    } else if (i != N - 1) {
      if (j == nj || j == nk) {
        A[j]++;
        A[k]--;
        ans[i] = j;
      } else {
        A[j]--;
        A[k]++;
        ans[i] = k;
      }
    } else {
      A[j]++;
      A[k]--;
      ans[i] = j;
    }
    j = nj;
    k = nk;
  }
  printf("Yes\\n");
  for (i = 0; i < N; i++) {
    printf("%c\\n", 'A' + ans[i]);
  }
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  vector<int> d(3);
  cin >> n >> d[0] >> d[1] >> d[2];
  vector<pair<int, int>> q;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int a = 0, b = 1;
    if (s == "AB")
      a = 0, b = 1;
    if (s == "AC")
      a = 0, b = 2;
    if (s == "BC")
      a = 1, b = 2;
    q.emplace_back(a, b);
  }
  string ans;
  auto add = [&](int a, int b) {
    d[a]++;
    d[b]--;
    ans += 'A' + a;
  };

  q.emplace_back(0, 1);
  for (int i = 0; i < n; i++) {
    int a = q[i].first;
    int b = q[i].second;
    if (!d[a] && !d[b]) {
      cout << "No" << endl;
      return 0;
    }
    if (!d[a]) {
      add(a, b);
    } else if (!d[b]) {
      add(b, a);
    } else {
      int na = q[i + 1].first;
      int nb = q[i + 1].second;
      if (a == na || a == nb) {
        add(a, b);
      } else {
        add(b, a);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, ko_do;
  vector<int> d(3);
  cin >> n >> d[0] >> d[1] >> d[2];
  vector<pair<int, int>> q;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int a = 0, b = 1;
    if (s == "AB")
      a = 0, b = 1;
    if (s == "AC")
      a = 0;
    b = 2;
    if (s == "BC")
      a = 1, b = 2;
    q.emplace_back(a, b);
  }
  string ans;
  auto add = [&](int a, int b) {
    d[a]++;
    d[b]--;
    ans += "A" + a;
  };

  q.emplace_back(0, 1);
  for (int i = 0; i < n; i++) {
    int a = q[i].first;
    int b = q[i].second;
    if (d[a] == 0 && d[b] == 0) {
      cout << "NO" << endl;
      return 0;
    }
    if (d[a] == 0) {
      add(a, b);
    } else if (d[b] == 0) {
      add(a, b);
    } else {
      int na = q[i + 1].first;
      int nb = q[i + 1].second;
      if (a == na || a == nb) {
        add(a, b);
      } else {
        add(b, a);
      }
    }
  }
  cout << "YES" << endl;
  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <array>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int main() {

  int N;
  array<int, 3> xs;
  vector<pair<int, int>> queries;
  vector<int> ans;
  scanf("%d%d%d%d", &N, &xs[0], &xs[1], &xs[2]);
  queries.resize(N);

  for (int i = 0; i < N; i++) {
    char buf[16];
    scanf("%s", buf);
    int i1 = buf[0] - 'A';
    int i2 = buf[1] - 'A';
    queries[i] = {i1, i2};
  }

  for (int step = 0; step < N; step++) {

    int i1 = queries[step].first;
    int i2 = queries[step].second;

    if (xs[i1] == 0 && xs[i2] == 0) {
      printf("No\\n");
      return 0;
    }

    if (xs[i1] == 1 && xs[i2] == 1 && step < N - 1) {

      int j1 = queries[step + 1].first;
      int j2 = queries[step + 1].second;

      if (i1 == j1 || i1 == j2) {
        swap(i1, i2);
      }

    } else {
      if (xs[i1] < xs[i2]) {
        swap(i1, i2);
      }
    }

    xs[i1] -= 1;
    xs[i2] += 1;
    ans.push_back(i2);
  }

  printf("Yes\\n");
  for (int i = 0; i < N; i++) {
    printf("%c\\n", ans[i] + 'A');
  }

  return 0;
}


Error: 0

Fixed submission:

#include <array>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int main() {

  int N;
  array<int, 3> xs;
  vector<pair<int, int>> queries;
  vector<int> ans;
  scanf("%d%d%d%d", &N, &xs[0], &xs[1], &xs[2]);
  queries.resize(N);

  for (int i = 0; i < N; i++) {
    char buf[16];
    scanf("%s", buf);
    int i1 = buf[0] - 'A';
    int i2 = buf[1] - 'A';
    queries[i] = {i1, i2};
  }

  if (xs[0] + xs[1] + xs[2] == 2) {
    return 1;
  }

  for (int step = 0; step < N; step++) {

    int i1 = queries[step].first;
    int i2 = queries[step].second;

    if (xs[i1] == 0 && xs[i2] == 0) {
      printf("No\\n");
      return 0;
    }

    if (xs[i1] == 1 && xs[i2] == 1 && step < N - 1) {

      int j1 = queries[step + 1].first;
      int j2 = queries[step + 1].second;

      if (i2 == j1 || i2 == j2) {
        swap(i1, i2);
      }

    } else {
      if (xs[i1] < xs[i2]) {
        swap(i1, i2);
      }
    }

    xs[i1] -= 1;
    xs[i2] += 1;
    ans.push_back(i2);
  }

  printf("Yes\\n");
  for (int i = 0; i < N; i++) {
    printf("%c\\n", ans[i] + 'A');
  }

  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MAX_N = 1e5;
int N, A, B, C;
string s[MAX_N];
char ans[MAX_N];

void dfs(int i, int a, int b, int c) {
  if (i >= N) {
    puts("Yes");
    rep(i, N) cout << ans[i] << endl;
    exit(0);
  }
  if (s[i] == "AB") {
    if (a)
      ans[i] = 'B', dfs(i + 1, a - 1, b + 1, c);
    if (b)
      ans[i] = 'A', dfs(i + 1, a + 1, b - 1, c);
  } else if (s[i] == "BC") {
    if (b)
      ans[i] = 'C', dfs(i + 1, a, b - 1, c + 1);
    if (c)
      ans[i] = 'B', dfs(i + 1, a, b + 1, c - 1);
  } else {
    if (a)
      ans[i] = 'C', dfs(i + 1, a - 1, b, c + 1);
    if (c)
      ans[i] = 'A', dfs(i + 1, a + 1, b, c - 1);
  }
}

int main() {
  cin >> N >> A >> B >> C;
  rep(i, N) cin >> s[i];
  dfs(0, A, B, C);
  puts("No");
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include<iostream>
// #include<map>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, (n))
typedef long long ll;
using namespace std;

int N, A, B, C;
vector<string> s;

int main() {
  cin >> N >> A >> B >> C;
  // set<tuple<int, int, int> > st;
  map<tuple<int, int, int>, string> st;
  st[tie(A, B, C)] = "";
  // st.insert(tie(A, B, C));
  rep(i, N) {
    string s;
    cin >> s;
    // set<tuple<int, int, int> > tmp;
    map<tuple<int, int, int>, string> tmp;
    for (auto j : st) {
      int a, b, c;
      tie(a, b, c) = j.first;
      // cout << a << " " << b << " " << c << endl;
      int pa = a + 1, pb = b + 1, pc = c + 1;
      int ma = a - 1, mb = b - 1, mc = c - 1;
      if (s == "AB") {
        if (b > 0) {
          // tmp.insert(tie(pa, mb, c));
          tmp[tie(pa, mb, c)] = st[j.first] + 'A';
          // cout << " AB: a++" << endl;
        }
        if (a > 0) {
          // tmp.insert(tie(ma, pb, c));
          tmp[tie(ma, pb, c)] = st[j.first] + 'B';
          // cout << " AB: b++" << endl;
        }
      } else if (s == "BC") {
        if (c > 0) {
          // tmp.insert(tie(a, pb, mc));
          tmp[tie(a, pb, mc)] = st[j.first] + 'B';
          // cout << " BC: b++" << endl;
        }
        if (b > 0) {
          // tmp.insert(tie(a, mb, pc));
          tmp[tie(a, mb, pc)] = st[j.first] + 'C';
          // cout << " BC: c++" << endl;
        }
      } else if (s == "AC") {
        if (c > 0) {
          // tmp.insert(tie(pa, b, mc));
          tmp[tie(pa, b, mc)] = st[j.first] + 'A';
          // cout << " AC: a++" << endl;
        }
        if (a > 0) {
          // tmp.insert(tie(ma, b, pc));
          tmp[tie(ma, b, pc)] = st[j.first] + 'C';
          // cout << " AC: c++" << endl;
        }
      }
    }
    st = tmp;
    // cout << tmp.size() << endl;
  }
  if (st.size() != 0) {
    cout << "Yes" << endl;
    // cout << st.begin() << endl;
    for (auto i : st) {
      string ans = i.second;
      for (char j : ans)
        cout << j << endl;
      break;
    }
  } else {
    cout << "No" << endl;
  }
}
Problem p02692 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n, a, b, c;
string s[100005];
char ans[100005];

bool ok;
void dfs(int ind, int a, int b, int c) {
  if (a < 0 || b < 0 || c < 0)
    return;
  if (ind == n) {
    puts("Yes");
    for (int i = 0; i < n; i++) {
      cout << ans[i] << endl;
    }
    exit(0);
  } else {
    if (s[ind] == "AB") {
      ans[ind] = 'A';
      dfs(ind + 1, a + 1, b - 1, c);
      ans[ind] = 'B';
      dfs(ind + 1, a - 1, b + 1, c);
    } else if (s[ind] == "AC") {
      ans[ind] = 'A';
      dfs(ind + 1, a + 1, b, c - 1);
      ans[ind] = 'C';
      dfs(ind + 1, a - 1, b, c + 1);
    } else {
      ans[ind] = 'B';
      dfs(ind + 1, a, b + 1, c - 1);
      ans[ind] = 'C';
      dfs(ind + 1, a, b - 1, c + 1);
    }
  }
}
int main() {
  cin >> n >> a >> b >> c;

  for (int i = 0; i < n; i++)
    cin >> s[i];
  dfs(0, a, b, c);

  puts("No");

  return 0;
}


Error: TLE

Fixed submission:

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

const string YES = "Yes";
const string NO = "No";

long long n;
vector<string> S;

void dfs(long long i, long long A, long long B, long long C, string str) {
  if (A < 0 || B < 0 || C < 0)
    return;
  if (i == n) {
    cout << "Yes" << endl;
    for (char c : str)
      cout << c << endl;
    exit(0);
  } else {
    if (S[i] == "AB") {
      dfs(i + 1, A + 1, B - 1, C, str + "A");
      dfs(i + 1, A - 1, B + 1, C, str + "B");
    } else if (S[i] == "AC") {
      dfs(i + 1, A + 1, B, C - 1, str + "A");
      dfs(i + 1, A - 1, B, C + 1, str + "C");
    } else {
      dfs(i + 1, A, B + 1, C - 1, str + "B");
      dfs(i + 1, A, B - 1, C + 1, str + "C");
    }
  }
}

void solve(long long N, long long A, long long B, long long C,
           std::vector<std::string> s) {
  n = N;
  S = s;
  dfs(0, A, B, C, "");
  cout << "No" << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  std::vector<std::string> s(N);
  for (int i = 0; i < N; i++) {
    std::cin >> s[i];
  }
  solve(N, A, B, C, std::move(s));
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

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

vector<string> s;
vector<string> ans;
int n;
void dfs(int com, int a, int b, int c) {
  if (a < 0 or b < 0 or c < 0)
    return;
  if (com == n + 1) {
    cout << "Yes\\n";
    for (int i = 1; i <= n; i++) {
      cout << ans[i] << '\\n';
    }
    exit(0);
  }
  if (s[com] == "AB") {
    ans[com] = "A";
    dfs(com + 1, a + 1, b - 1, c);
    ans[com] = "B";
    dfs(com + 1, a - 1, b + 1, c);
  } else if (s[com] == "AC") {
    ans[com] = "A";
    dfs(com + 1, a + 1, b, c - 1);
    ans[com] = "C";
    dfs(com + 1, a - 1, b, c + 1);
  } else {
    ans[com] = "B";
    dfs(com + 1, a, b + 1, c - 1);
    ans[com] = "C";
    dfs(com + 1, a, b - 1, c + 1);
  }
}

int main() {
  int i, a, b, c;
  cin >> n >> a >> b >> c;
  s.resize(n + 1);
  ans.resize(n + 1);
  for (i = 1; i <= n; i++) {
    cin >> s[i];
  }
  dfs(1, a, b, c);
  cout << "No";
  return 0;
}


Error: 0

Fixed submission:

// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define FOR(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for (int i = 0; i < n; i++)
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max3(a, max(b, c), d)
#define max5(a, b, c, d, e) max4(a, max(b, c), d, e)
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min3(a, min(b, c), d)
#define min5(a, b, c, d, e) min4(a, min(b, c), d, e)
#define sec second
#define fir first
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repe(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI 3.14159265358979323846 /* pi */
#define pb push_back
#define pii pair<int, int>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
std::vector<string> que(100005);
std::vector<char> k(100005);
ll n;
ll dp(ll a, ll b, ll c, ll i) {
  if (a < 0 || b < 0 || c < 0) {
    return 0;
  }
  if (i == n) {
    cout << "Yes\\n";
    for (int i = 0; i < n; i++)
      cout << k[i] << endl;
    // cout<<"yo";
    exit(0);
  } else {
    if (que[i] == "AB") {
      k[i] = 'A';
      dp(a + 1, b - 1, c, i + 1);
      k[i] = 'B';
      dp(a - 1, b + 1, c, i + 1);
    } else if (que[i] == "AC") {
      k[i] = 'A';
      dp(a + 1, b, c - 1, i + 1);
      k[i] = 'C';
      dp(a - 1, b, c + 1, i + 1);
    } else {
      k[i] = 'B';
      dp(a, b + 1, c - 1, i + 1);
      k[i] = 'C';
      dp(a, b - 1, c + 1, i + 1);
    }
  }
}
int main() {
  fast cin >> n;
  ll a, b, c;
  cin >> a >> b >> c;
  for (ll i = 0; i < n; i++) {
    cin >> que[i];
  }

  dp(a, b, c, 0);
  cout << "No\\n";

  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
const int N = 1e5 + 10;

int n;
char ans[N];
string str[N];

void dfs(int i, int a, int b, int c) {
  if (i > n) {
    puts("Yes");
    for (int i = 1; i <= n; i++)
      putchar(ans[i]), puts("");
    exit(0);
  }
  if (str[i] == "AB") {
    if (a)
      ans[i] = 'B', dfs(i + 1, a - 1, b + 1, c);
    if (b)
      ans[i] = 'A', dfs(i + 1, a + 1, b - 1, c);
  } else if (str[i] == "AC") {
    if (a)
      ans[i] = 'C', dfs(i + 1, a - 1, b, c + 1);
    if (c)
      ans[i] = 'A', dfs(i + 1, a + 1, b, c - 1);
  } else {
    if (b)
      ans[i] = 'C', dfs(i + 1, a, b - 1, c + 1);
    if (c)
      ans[i] = 'B', dfs(i + 1, a, b + 1, c - 1);
  }
}

int main() {
  scanf("%d", &n);
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  for (int i = 1; i <= n; i++)
    cin >> str[i];
  dfs(1, a, b, c);
  puts("No");
  exit(0);
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc                                                                     \\
  getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int, int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5 + 10, size = 1 << 20;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o &x) {
  char c = gc;
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = gc;
  }
  while (isdigit(c))
    x = x * 10 + c - '0', c = gc;
  x *= f;
}
template <class o> void qw(o x) {
  if (x / 10)
    qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
  if (x < 0)
    x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o> void pr2(o x) {
  if (x < 0)
    x = -x, putchar('-');
  qw(x);
  puts("");
}

int n, ans[N], a[4], flag = 1, ed;
char str[N][4];
vector<int> t(3), v(3);
int s[6], top, c[6], b[4];

void dfs(int x) {
  if (x > ed) {
    vector<int> tmp(3);
    tmp = {a[0], a[1], a[2]};
    sort(tmp.begin(), tmp.end());
    if (tmp > t)
      t = tmp, c[1] = s[1], c[2] = s[2], c[3] = s[3], b[0] = a[0], b[1] = a[1],
      b[2] = a[2];
    return;
  }
  int y = str[x][0], z = str[x][1];
  if (a[y])
    a[y]--, a[z]++, s[++top] = y, dfs(x + 1), a[y]++, a[z]--;
  if (a[z])
    a[z]--, a[y]++, s[++top] = z, dfs(x + 1), a[y]--, a[z]++;
}

int main() {
  qr(n);
  for (int i = 0; i < 3; i++)
    qr(a[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str[i]);
    int x = (str[i][0] -= 'A');
    int y = (str[i][1] -= 'A');
  }
  int i;
  for (i = 1; i <= n; i += 3) {
    ed = min(n, i + 2);
    t = {-1, 0, 0};
    dfs(i);
    a[0] = b[0];
    a[1] = b[1];
    a[2] = b[2];
    ans[i] = c[1];
    ans[i + 1] = c[2];
    ans[i + 2] = c[3];
    if (t[0] < 0)
      puts("No"), exit(0);
  }
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%c\\n", ans[i] + 'A');
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

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

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 1e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n, a, b, c;
int ans[N];
char s[N][3];

void dfs(int u, int a, int b, int c) {
  if (u > n) {
    puts("Yes");
    Rep(i, 1, n) printf("%c\\n", ans[i] + 'A');
    exit(0);
  }
  if (s[u][0] == 'A' && s[u][1] == 'B') {
    if (a)
      ans[u] = 1, dfs(u + 1, a - 1, b + 1, c);
    if (b)
      ans[u] = 0, dfs(u + 1, a + 1, b - 1, c);
  }
  if (s[u][0] == 'A' && s[u][1] == 'C') {
    if (a)
      ans[u] = 2, dfs(u + 1, a - 1, b, c + 1);
    if (c)
      ans[u] = 0, dfs(u + 1, a + 1, b, c - 1);
  }
  if (s[u][0] == 'B' && s[u][1] == 'C') {
    if (b)
      ans[u] = 2, dfs(u + 1, a, b - 1, c + 1);
    if (c)
      ans[u] = 1, dfs(u + 1, a, b + 1, c - 1);
  }
}

int main() {
  read(n), read(a), read(b), read(c);
  Rep(i, 1, n) scanf("%s", s[i]);
  dfs(1, a, b, c);
  puts("No");
  return 0;
}

Error: 0

Fixed submission:

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

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 1e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n, a[3];
char ans[N];
char s[N][3];
int cnt[3];
int zero;

int main() {
  read(n), read(a[0]), read(a[1]), read(a[2]);
  Rep(i, 1, n) scanf("%s", s[i]);
  Rep(i, 0, 2) if (!a[i]) zero++;
  if (zero == 3)
    return puts("No"), 0;
  if (zero == 2)
    if (!a[s[1][0] - 'A'] && !a[s[1][1] - 'A'])
      return puts("No"), 0;
  Rep(i, 1, n) {
    int x = s[i][0] - 'A', y = s[i][1] - 'A';
    if (a[x] < a[y])
      ans[i] = s[i][0], a[x]++, a[y]--;
    else
      ans[i] = s[i][1], a[x]--, a[y]++;
    if (a[x] < 0 || a[y] < 0)
      return puts("No");
  }
  puts("Yes");
  Rep(i, 1, n) printf("%c\\n", ans[i]);
  return 0;
}