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

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()

#define ll long long
#define ld long double

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  map<char, int> ma;
  cin >> n >> ma['A'] >> ma['B'] >> ma['C'];
  vector<string> q(n);
  for (int i = 0; i < n; ++i)
    cin >> q[i];
  vector<map<char, int>> pr(n + 1);
  pr[0] = ma;
  string ans = "";
  for (int i = 0; i < n; ++i) {
    string s = q[i];
    if (ma[s[0]] == 0 && ma[s[1]] == 0) {
      if (i == 0) {
        cout << "No\\n";
        return 0;
      }
      if (q[i - 1][1] == s[0] || q[i - 1][1] == s[1])
        swap(q[i - 1][1], q[i - 1][0]);
      if (pr[i - 1][q[i - 1][1]] == 0) {
        cout << "No\\n";
        return 0;
      }
      ans.back() = q[i - 1][0];
      pr[i][q[i - 1][1]] -= 2;
      pr[i][q[i - 1][0]] += 2;
      ma = pr[i];
      char ch = 'A';
      while (ch == q[i - 1][0] || ch == q[i - 1][1])
        ++ch;
      ans.pb(ch);
      ++ma[ch];
      --ma[q[i - 1][0]];
    } else {
      if (ma[s[0]] == 0) {
        ans.pb(s[0]);
        ++ma[s[0]];
        --ma[s[1]];
      } else {
        ans.pb(s[1]);
        ++ma[s[1]];
        --ma[s[0]];
      }
    }
    pr[i + 1] = ma;
  }
  cout << "Yes\\n";
  for (auto x : ans)
    cout << x << '\\n';
  return 0;
}


Error: 0

Fixed submission:

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()

#define ll long long
#define ld long double

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  map<char, int> ma;
  cin >> n >> ma['A'] >> ma['B'] >> ma['C'];
  vector<string> q(n);
  for (int i = 0; i < n; ++i)
    cin >> q[i];
  vector<map<char, int>> pr(n + 1);
  pr[0] = ma;
  string ans = "";
  for (int i = 0; i < n; ++i) {
    string s = q[i];
    if (ma[s[0]] == 0 && ma[s[1]] == 0) {
      if (i == 0) {
        cout << "No\\n";
        return 0;
      }
      assert(q[i - 1][1] != s[0] && q[i - 1][1] != s[1]);
      if (pr[i - 1][q[i - 1][1]] == 0) {
        cout << "No\\n";
        return 0;
      }
      ans.back() = q[i - 1][0];
      pr[i][q[i - 1][1]] -= 2;
      pr[i][q[i - 1][0]] += 2;
      ma = pr[i];
      char ch = 'A';
      while (ch == q[i - 1][0] || ch == q[i - 1][1])
        ++ch;
      ans.pb(ch);
      ++ma[ch];
      --ma[q[i - 1][0]];
    } else {
      if (ma[s[0]] == 0) {
        ans.pb(s[0]);
        ++ma[s[0]];
        --ma[s[1]];
      } else {
        ans.pb(s[1]);
        ++ma[s[1]];
        --ma[s[0]];
      }
    }
    pr[i + 1] = ma;
  }
  cout << "Yes\\n";
  for (auto x : ans)
    cout << x << '\\n';
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
using LL = long long;

constexpr int MAXN = 1e5 + 5;

template <typename T> inline void read(T &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f = (ch == '-') ? -1 : 1, ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - 48, ch = getchar();
  x *= f;
}

int n, val[4], u[MAXN], v[MAXN];
string opt[MAXN];
vector<char> choice;

int main() {
  // freopen("test.in", "r", stdin);
  // freopen("test.out", "w", stdout);
  boost;
  cin >> n;
  cin >> val[1] >> val[2] >> val[3];
  for (int i = 1; i <= n; i++) {
    cin >> opt[i];
    if (opt[i] == "AB")
      u[i] = 1, v[i] = 2;
    else if (opt[i] == "AC")
      u[i] = 1, v[i] = 3;
    else
      u[i] = 2, v[i] = 3;
  }
  for (int i = 1; i < n; i++) {
    if (!val[u[i]] && !val[v[i]]) {
      cout << "No" << endl;
      return 0;
    }
    if (val[u[i]] < val[v[i]]) {
      val[u[i]]++, val[v[i]]--;
      choice.push_back(u[i] - 1 + 'A');
    } else if (val[u[i]] > val[v[i]]) {
      val[u[i]]--, val[v[i]]++;
      choice.push_back(v[i] - 1 + 'A');
    } else {
      val[u[i]]++, val[v[i]]--;
      if (!val[u[i + 1]] && !val[v[i + 1]]) {
        val[u[i]]--, val[v[i]]++;
      } else {
        choice.push_back(u[i] - 1 + 'A');
        continue;
      }
      val[u[i]]--, val[v[i]]++;
      if (!val[u[i + 1]] && !val[v[i + 1]]) {
        val[u[i]]++, val[v[i]]--;
      } else
        choice.push_back(v[i] - 1 + 'A');
    }
  }
  if (!val[u[n]] && !val[v[n]]) {
    cout << "No" << endl;
    return 0;
  }
  if (val[u[n]])
    choice.push_back(v[n] - 1 + 'A');
  else
    choice.push_back(u[n] - 1 + 'A');
  cout << "Yes" << endl;
  for (auto &c : choice)
    cout << c << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
using LL = long long;

constexpr int MAXN = 1e5 + 5;

template <typename T> inline void read(T &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f = (ch == '-') ? -1 : 1, ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - 48, ch = getchar();
  x *= f;
}

int n, p[3];
string opt[MAXN];
vector<char> choice;

int main() {
  // freopen("test.in", "r", stdin);
  // freopen("test.out", "w", stdout);
  boost;
  cin >> n;
  cin >> p[1] >> p[2] >> p[3];
  for (int i = 1; i <= n; i++)
    cin >> opt[i];
  for (int i = 1; i <= n; i++) {
    int u, v;
    if (opt[i] == "AB")
      u = 1, v = 2;
    else if (opt[i] == "AC")
      u = 1, v = 3;
    else
      u = 2, v = 3;
    if (!p[u] && !p[v]) {
      cout << "No" << endl;
      return 0;
    }
    if (p[u] < p[v]) {
      p[u]++, p[v]--;
      choice.push_back(u - 1 + 'A');
    } else {
      p[u]--, p[v]++;
      choice.push_back(v - 1 + 'A');
    }
  }
  cout << "Yes" << endl;
  for (auto &c : choice)
    cout << c << endl;
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#define mem(x) memset(x, 0, sizeof(x))
#define sca(x) scanf("%d", &x)
#define scaa(x, y) scanf("%d%d", &x, &y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-6;
typedef pair<long, long> pll;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<char, char> pcc;
string s[100005];
char ans[100005];
int n, a, b, c;
void dfs(int i, int a, int b, int c) {
  if (i == n) {
    cout << "Yes\\n";
    for (int i = 0; i < n; i++)
      cout << ans[i] << "\\n";
    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);
  }
  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);
  }
  if (s[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);
  }
}

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

Error: -11

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#define mem(x) memset(x, 0, sizeof(x))
#define sca(x) scanf("%d", &x)
#define scaa(x, y) scanf("%d%d", &x, &y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-6;
typedef pair<long, long> pll;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<char, char> pcc;
string s[100005];
char ans[100005];
int n, a, b, c, f = 0;
int dfs(int i, int a, int b, int c) {
  if (i == n) {
    cout << "Yes\\n";
    for (int i = 0; i < n; i++)
      cout << ans[i] << "\\n";
    f = 1;
    return 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] == "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 (s[i] == "BC") {
    if (c) {
      ans[i] = 'B';
      dfs(i + 1, a, b + 1, c - 1);
    }
    if (b) {
      ans[i] = 'C';
      dfs(i + 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);
  if (f == 0)
    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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
const int N = 1e5 + 10;

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

void dfs(int i, int a, int b, int c) {
  if (i > n) {
    ok = true;
    return;
  }
  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);
  if (ok) {
    puts("Yes");
    for (int i = 1; i <= n; i++)
      putchar(ans[i]), puts("");
  } else {
    puts("No");
  }
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
const ll MOD = 1000000007, MOD2 = 998244353, INF = 1e18;

int main() {
  ll N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<ll> ABC = {A, B, C};
  vector<string> s(N);
  rep(i, N) { cin >> s.at(i); }
  vector<char> choice(N);
  rep(i, N) {
    int x = s.at(i).at(0) - 'A', y = s.at(i).at(1) - 'A';
    if (ABC.at(x) == 0 && ABC.at(y) == 0) {
      cout << "No" << endl;
      return 0;
    }
    if (ABC.at(x) > ABC.at(y)) {
      choice.at(i) = y + 'A';
      ABC.at(x)--;
      ABC.at(y)++;
    } else if (ABC.at(y) > ABC.at(x)) {
      choice.at(i) = x + 'A';
      ABC.at(y)--;
      ABC.at(x)++;
    } else {
      if (ABC.at(x) == 1 && ABC.at(3 - x - y) == 0 && i < N - 1) {
        if (s.at(i) == s.at(i + 1)) {
          choice.at(i) = y + 'A';
          ABC.at(x)--;
          ABC.at(y)++;
        } else {
          int nx = s.at(i + 1).at(0) - 'A', ny = s.at(i + 1).at(1) - 'A';
          choice.at(i) = x + y - 3 + nx + ny + 'A';
          ABC.at(3 - nx - ny)--;
          ABC.at(x + y - 3 + nx + ny)++;
        }
      } else {
        choice.at(i) = y + 'A';
        ABC.at(x)--;
        ABC.at(y)++;
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, N) { cout << choice.at(i) << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
const ll MOD = 1000000007, MOD2 = 998244353, INF = 1e18;

int main() {
  ll N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<ll> ABC = {A, B, C};
  vector<string> s(N);
  rep(i, N) { cin >> s.at(i); }
  vector<char> choice(N);
  rep(i, N) {
    int x = s.at(i).at(0) - 'A', y = s.at(i).at(1) - 'A';
    if (ABC.at(x) == 0 && ABC.at(y) == 0) {
      cout << "No" << endl;
      return 0;
    }
    if (ABC.at(x) > ABC.at(y)) {
      choice.at(i) = y + 'A';
      ABC.at(x)--;
      ABC.at(y)++;
    } else if (ABC.at(y) > ABC.at(x)) {
      choice.at(i) = x + 'A';
      ABC.at(y)--;
      ABC.at(x)++;
    } else {
      if (ABC.at(x) == 1 && ABC.at(3 - x - y) == 0 && i < N - 1) {
        if (s.at(i) == s.at(i + 1)) {
          choice.at(i) = y + 'A';
          ABC.at(x)--;
          ABC.at(y)++;
        } else {
          int nx = s.at(i + 1).at(0) - 'A', ny = s.at(i + 1).at(0) - 'A';
          choice.at(i) = x + y - 3 + nx + ny + 'A';
          ABC.at(3 - nx - ny)--;
          ABC.at(x + y - 3 + nx + ny)++;
        }
      } else {
        choice.at(i) = y + 'A';
        ABC.at(x)--;
        ABC.at(y)++;
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, N) { cout << choice.at(i) << endl; }
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec)
    is >> v;
  return is;
}
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < (int)(N); i++)

void solve() {
  int N;
  vector<int> D(3);
  cin >> N >> D;
  vector<string> s(N);
  cin >> s;

  vector<char> ans;
  rep(i, N) {
    int first = s[i][0] - 'A';
    int second = s[i][1] - 'A';
    if (D[first] == 0 and D[second] == 0) {
      cout << "No" << endl;
      return;
    }

    int greater;
    int less;

    int rest = 0 + 1 + 2 - first - second;
    if (D[first] == 1 and D[second] == 1 and i + 1 < N and
        count(all(s[i + 1]), (char)('A' + rest)) == 1) {
      if (count(all(s[i + 1]), (char)('A' + first)) == 1) {
        greater = second;
        less = first;
      } else {
        greater = first;
        less = second;
      }
    } else if (D[first] >= D[second]) {
      greater = first;
      less = second;
    } else {
      greater = second;
      less = first;
    }

    D[greater]--;
    D[less]++;
    ans.push_back('A' + less);
  }
  cout << "Yes" << endl;
  rep(i, N) cout << ans[i] << endl;
}

int main() {
  solve();
  return 0;
}


Error: 0

Fixed submission:

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec)
    is >> v;
  return is;
}
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < (int)(N); i++)

void solve() {
  int N;
  vector<int> D(3);
  cin >> N >> D;
  vector<string> s(N);
  cin >> s;

  vector<char> ans;
  rep(i, N) {
    int first = s[i][0] - 'A';
    int second = s[i][1] - 'A';
    if (D[first] == 0 and D[second] == 0) {
      cout << "No" << endl;
      return;
    }

    int greater;
    int less;

    if (D[first] == 1 and D[second] == 1 and i + 1 < N) {
      int rest = 0 + 1 + 2 - first - second;
      if (count(all(s[i + 1]), (char)('A' + rest)) == 1) {
        if (count(all(s[i + 1]), (char)('A' + first)) == 1) {
          greater = second;
          less = first;
        } else {
          greater = first;
          less = second;
        }
      }
    } else if (D[first] >= D[second]) {
      greater = first;
      less = second;
    } else {
      greater = second;
      less = first;
    }

    D[greater]--;
    D[less]++;
    ans.push_back('A' + less);
  }
  cout << "Yes" << endl;
  rep(i, N) cout << ans[i] << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];
  vector<char> ans;
  string s[100001];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  for (int i = 0; i < n; i++) {
    if (!a[s[i][0] - 'A'] && !a[s[i][1] - 'A']) {
      cout << "No" << endl;
      return 0;
    } else if (a[s[i][0] - 'A'] > a[s[i][1] - 'A']) {
      a[s[i][0] - 'A']--, a[s[i][1] - 'A']++;
      ans.push_back(s[i][1]);
    } else if (a[s[i][0] - 'A'] < a[s[i][1] - 'A']) {
      a[s[i][0] - 'A']++, a[s[i][1] - 'A']--;
      ans.push_back(s[i][0]);
    } else if (a[s[i][0] - 'A'] == a[s[i][1] - 'A']) {
      if (i == n - 1 || s[i][0] == s[i + 1][0] || s[i][0] == s[i + 1][1]) {
        a[s[i][0] - 'A']++, a[s[i][1] - 'A']--;
        ans.push_back(s[i][0]);
      } else {
        a[s[i][0] - 'A']--, a[s[i][1] - 'A']++;
        ans.push_back(s[i][1]);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];
  vector<char> ans;
  string s[100001];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  for (int i = 0; i < n; i++) {
    if (!a[s[i][0] - 'A'] && !a[s[i][1] - 'A']) {
      cout << "No" << endl;
      return 0;
    }
    if (a[s[i][0] - 'A'] > a[s[i][1] - 'A']) {
      a[s[i][0] - 'A']--, a[s[i][1] - 'A']++;
      ans.push_back(s[i][1]);
    } else if (a[s[i][0] - 'A'] < a[s[i][1] - 'A']) {
      a[s[i][0] - 'A']++, a[s[i][1] - 'A']--;
      ans.push_back(s[i][0]);
    } else {
      if (i == n - 1 || s[i][0] == s[i + 1][0] || s[i][0] == s[i + 1][i]) {
        a[s[i][0] - 'A']++, a[s[i][1] - 'A']--;
        ans.push_back(s[i][0]);
      } else {
        a[s[i][0] - 'A']--, a[s[i][1] - 'A']++;
        ans.push_back(s[i][1]);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;

char s[6];
char ans[100005];
int n, x[100005], y[100005];
int dp[100005][7][7][7];

int dfs(int i, int a0, int a1, int a2) {
  int a[3];
  if (i > n)
    return 1;
  a[0] = a0;
  a[1] = a1;
  a[2] = a2;
  if (dp[i][a0][a1][a2])
    return -1;
  if (a[x[i]] == 0 && a[y[i]] == 0)
    return dp[i][a0][a1][a2] = -1;
  a[0] = a0;
  a[1] = a1;
  a[2] = a2;
  if (a[y[i]] != 0) {
    a[y[i]]--;
    a[x[i]]++;
    if (dfs(i + 1, a[0], a[1], a[2]) == 1) {
      ans[i] = x[i] + 'A';
      return 1;
    }
  }
  a[0] = a0;
  a[1] = a1;
  a[2] = a2;
  if (a[x[i]] != 0) {
    a[x[i]]--;
    a[y[i]]++;
    if (dfs(i + 1, a[0], a[1], a[2]) == 1) {
      ans[i] = y[i] + 'A';
      return 1;
    }
  }
  return dp[i][a0][a1][a2] = -1;
}

int main() {
  int a, b, c;
  scanf("%d%d%d%d", &n, &a, &b, &c);
  a = min(2, a);
  b = min(2, b);
  c = min(2, c);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    x[i] = s[0] - 'A';
    y[i] = s[1] - 'A';
  }
  if (dfs(1, a, b, c) == -1)
    printf("No\\n");
  else {
    printf("Yes\\n");
    for (int i = 1; i <= n; i++)
      printf("%c\\n", ans[i]);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mz 998244353
#define pq priority_queue
using namespace std;

char s[6];
char ans[100005];
int n, x[100005], y[100005];
int a[6];

bool dfs(int i) {
  if (i > n)
    return 1;
  if (a[x[i]] == 0 && a[y[i]] == 0)
    return 0;
  if (a[x[i]] >= a[y[i]]) {
    ans[i] = 'A' + y[i];
    a[y[i]]++;
    a[x[i]]--;
    if (dfs(i + 1))
      return 1;
    a[y[i]]--;
    a[x[i]]++;
  } else {
    ans[i] = 'A' + x[i];
    a[x[i]]++;
    a[y[i]]--;
    if (dfs(i + 1))
      return 1;
    a[x[i]]--;
    a[y[i]]++;
  }
  return 0;
}

int main() {
  scanf("%d%d%d%d", &n, &a[0], &a[1], &a[2]);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    x[i] = s[0] - 'A';
    y[i] = s[1] - 'A';
  }
  if (!dfs(1)) {
    while (a[0] + a[1] + a[2] >= 2)
      ;
    printf("No\\n");
  } else {
    printf("Yes\\n");
    for (int i = 1; i <= n; i++)
      printf("%c\\n", ans[i]);
  }
  return 0;
}
/*
5 6 9 1
BC
AC
BC
AB
AB
*/
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, z, n) for (ll i = z; i <= n; i++)
#define repl(i, z, n) for (ll i = z; i < n; i++)
#define all(v) v.begin(), v.end()
#define STR(var) #var
typedef long long ll;

using namespace std;

int main() {
  vector<int> a = vector<int>(3);
  vector<int> res;
  int n;
  cin >> n;
  vector<string> s = vector<string>(n);
  repl(i, 0, 3) cin >> a[i];
  repl(i, 0, n) cin >> s[i];

  if (accumulate(all(a), 0) == 0) {
    cout << "No\\n";
    return 0;
  }
  repl(i, 0, n) {
    int x = s[i][0] - 'A';
    int y = s[i][1] - 'A';
    if (i < n - 1 && a[x] == 1 && a[y] == 1) {
      bool found_x = (x == (s[i + 1][0] - 'A') || x == (s[i + 1][1] - 'A'));
      // bool found_y=(y==(s[i+1][0]-'A') || y==(s[i+1][1]-'A'));
      if (found_x) {
        a[x]++;
        a[y]--;
        res.push_back(x);
      } else {
        a[x]--;
        a[y]++;
        res.push_back(y);
      }
    } else {
      if (a[x] <= 0 && a[y] <= 0) {
        cout << "No\\n";
        return 0;
      }
      if (a[x] < a[y]) {
        a[x]++;
        a[y]--;
        res.push_back(x);
      } else {
        a[y]++;
        a[x]--;
        res.push_back(y);
      }
    }
    // cout << a[0] << a[1] << a[2] << endl;
  }
  cout << "Yes\\n";
  for (int i : res) {
    cout << char(i + 'A') << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, z, n) for (ll i = z; i <= n; i++)
#define repl(i, z, n) for (ll i = z; i < n; i++)
#define all(v) v.begin(), v.end()
#define STR(var) #var
typedef long long ll;

using namespace std;

int main() {
  vector<int> a = vector<int>(3);
  vector<int> res;
  int n;
  cin >> n;
  vector<string> s = vector<string>(n);
  repl(i, 0, 3) cin >> a[i];
  repl(i, 0, n) cin >> s[i];

  if (accumulate(all(a), 0) == 0) {
    cout << "No\\n";
    exit(1);
  }
  repl(i, 0, n) {
    int x = s[i][0] - 'A';
    int y = s[i][1] - 'A';
    int other = 0 + 1 + 2 - x - y;
    if (i < n - 1 && a[x] == 1 && a[y] == 1) {
      bool found_x = (x == (s[i + 1][0] - 'A') || x == (s[i + 1][1] - 'A'));
      bool found_y = (y == (s[i + 1][0] - 'A') || y == (s[i + 1][1] - 'A'));
      if (found_x) {
        a[x]++;
        a[y]--;
        res.push_back(x);
      } else {
        a[x]--;
        a[y]++;
        res.push_back(y);
      }
    } else {
      if (a[x] <= 0 && a[y] <= 0) {
        cout << "No\\n";
        return 0;
      }
      if (a[x] < a[y]) {
        a[x]++;
        a[y]--;
        res.push_back(x);
      } else {
        a[y]++;
        a[x]--;
        res.push_back(y);
      }
    }
    // cout << a[0] << a[1] << a[2] << endl;
  }
  cout << "Yes\\n";
  for (int i : res) {
    cout << char(i + 'A') << endl;
  }
  return 0;
}