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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

using namespace std;

class Index {
public:
  Index(){};
  Index(string s) { set(s); };
  ~Index(){};

  int x, y, z;

  void set(string s) {
    if (s == "AB") {
      x = 0;
      y = 1;
      z = 2;
    } else if (s == "AC") {
      x = 0;
      y = 2;
      z = 1;
    } else {
      x = 1;
      y = 2;
      z = 0;
    }
  }
};

int main() {
  int n;
  vector<int> abc(3, 0);
  string s_abc = "ABC";
  cin >> n >> abc[0] >> abc[1] >> abc[2];

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

  Index idx1, idx2;
  for (int i = 0; i < n; i++) {
    idx1.set(vs[i]);

    if (abc[idx1.x] > abc[idx1.y]) {
      swap(idx1.x, idx1.y);
    }

    abc[idx1.x]++;
    abc[idx1.y]--;
    ans.push_back(s_abc[idx1.x]);
    if (i != n - 1) {
      idx2.set(vs[i + 1]);

      if (abc[idx2.x] <= 0 && abc[idx2.y] <= 0) {
        // 戻す
        abc[idx1.x]--;
        abc[idx1.y]++;

        // 加減を逆に
        abc[idx1.x]--;
        abc[idx1.y]++;
        ans.back() = s_abc[idx1.y];
      }
    }

    if (abc[0] < 0 || abc[1] < 0 || abc[2] < 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (char c : ans) {
    cout << c << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

using namespace std;

class Index {
public:
  Index(){};
  Index(string s) { set(s); };
  ~Index(){};

  int x, y, z;

  void set(string s) {
    if (s == "AB") {
      x = 0;
      y = 1;
      z = 2;
    } else if (s == "AC") {
      x = 0;
      y = 2;
      z = 1;
    } else {
      x = 1;
      y = 2;
      z = 0;
    }
  }

  bool is_ok() { return x >= 0 && y >= 0 && z >= 0; }
};

int main() {
  int n;
  vector<int> abc(3, 0);
  string s_abc = "ABC";
  cin >> n >> abc[0] >> abc[1] >> abc[2];

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

  Index idx1, idx2;
  for (int i = 0; i < n; i++) {
    idx1.set(vs[i]);

    if (abc[idx1.x] > abc[idx1.y]) {
      swap(idx1.x, idx2.y);
    }

    abc[idx1.x]++;
    abc[idx1.y]--;
    ans.push_back(s_abc[idx1.x]);
    if (i != n - 1) {
      idx2.set(vs[i + 1]);

      if (abc[idx2.x] <= 0 && abc[idx2.y] <= 0) {
        // 戻す
        abc[idx1.x]--;
        abc[idx1.y]++;

        // 加減を逆に
        abc[idx1.x]--;
        abc[idx1.y]++;
        ans.back() = s_abc[idx1.y];
      }
    }

    if (!idx1.is_ok()) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (char c : ans) {
    cout << c << endl;
  }
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

char other(char a, char b) {
  if (a != 'C' && b != 'C') {
    return 'C';
  }
  if (a == 'B' && b != 'B') {
    return 'B';
  }
  return 'A';
}

string req[200005];
int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;

  vector<char> ans;
  vector<int> cnt(255, 0);
  cnt['A'] = a;
  cnt['B'] = b;
  cnt['C'] = c;
  int k = (a == 0) + (b == 0) + (c == 0);
  for (int i = 0; i < n; i++) {
    cin >> req[i];
  }
  for (int i = 0; i < n; i++) {
    string s = req[i];
    assert(cnt['A'] >= 0 && cnt['B'] >= 0 && cnt['C'] >= 0);
    if (cnt[s[0]] == 0 && cnt[s[1]] == 0) {
      cout << "No";
      return 0;
    }
    if (cnt[s[0]] == 0) {
      ans.push_back(s[0]);
      cnt[s[0]] = 1;
      cnt[s[1]]--;
      continue;
    }
    if (cnt[s[1]] == 0) {
      ans.push_back(s[1]);
      cnt[s[1]] = 1;
      cnt[s[0]]--;
      continue;
    }
    if (cnt[s[0]] == 1 && cnt[s[1]] == 1) {
      char c = other(s[0], s[1]);
      if (i == n - 1 || req[i] == req[i + 1] ||
          (req[i + 1][0] == s[0] || req[i + 1][1] == s[0])) {
        ans.push_back(s[0]);
        cnt[s[0]]++;
        cnt[s[1]]--;
      } else {
        ans.push_back(s[1]);
        cnt[s[1]]++;
        cnt[s[0]]--;
      }
      continue;
    }
    if (cnt[s[1]] > cnt[s[0]]) {
      ans.push_back(s[0]);
      cnt[s[0]]++;
      cnt[s[1]]--;
    } else {
      ans.push_back(s[1]);
      cnt[s[1]]++;
      cnt[s[0]]--;
    }
  }
  cout << "Yes\\n";
  for (int i = 0; i < n; i++) {
    cout << ans[i] << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

char other(char a, char b) {
  if (a != 'C' && b != 'C') {
    return 'C';
  }
  if (a == 'B' && b != 'B') {
    return 'B';
  }
  return 'A';
}

string req[200005];
int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;

  vector<char> ans;
  vector<int> cnt(255, 0);
  cnt['A'] = a;
  cnt['B'] = b;
  cnt['C'] = c;
  int k = (a == 0) + (b == 0) + (c == 0);
  for (int i = 0; i < n; i++) {
    cin >> req[i];
  }
  for (int i = 0; i < n; i++) {
    string s = req[i];
    if (cnt[s[0]] == 0 && cnt[s[1]] == 0) {
      assert(k < 3);
      cout << "No";
      return 0;
    }
    if (cnt[s[0]] == 0) {
      ans.push_back(s[0]);
      cnt[s[0]] = 1;
      cnt[s[1]]--;
      continue;
    }
    if (cnt[s[1]] == 0) {
      ans.push_back(s[1]);
      cnt[s[1]] = 1;
      cnt[s[0]]--;
      continue;
    }
    if (cnt[s[0]] == 1 && cnt[s[1]] == 1) {
      char c = other(s[0], s[1]);
      if (i == n - 1 || req[i] == req[i + 1] ||
          (req[i + 1][0] == s[0] && req[i + 1][1] == s[0])) {
        ans.push_back(s[0]);
        cnt[s[0]]++;
        cnt[s[1]]--;
      } else {
        ans.push_back(s[1]);
        cnt[s[1]]++;
        cnt[s[0]]--;
      }
      continue;
    }
    if (cnt[s[1]] > cnt[s[0]]) {
      ans.push_back(s[0]);
      cnt[s[0]]++;
      cnt[s[1]]--;
    } else {
      ans.push_back(s[1]);
      cnt[s[1]]++;
      cnt[s[0]]--;
    }
  }
  cout << "Yes\\n";
  for (int i = 0; i < n; i++) {
    cout << ans[i] << "\\n";
  }
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  ll n, a, b, c;
  cin >> n;
  cin >> a >> b >> c;
  vector<char> move;
  map<char, ll> data;
  data['A'] = a;
  data['B'] = b;
  data['C'] = c;
  string choices[n];
  for (int i = 0; i < n; i++) {
    cin >> choices[i];
  }
  if (a == 0 && b == 0 && c == 0) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < n - 1; i++) {
    char ch_1 = choices[i][0];
    char ch_2 = choices[i][1];
    if (data[ch_1] == 0) {
      data[ch_1] += 1;
      move.push_back(ch_1);
      data[ch_2] -= 1;
    } else if (data[ch_2] == 0) {
      data[ch_2] += 1;
      move.push_back(ch_2);
      data[ch_1] -= 1;
    } else {
      if (ch_1 == choices[i + 1][0] || ch_1 == choices[i + 1][1]) {
        data[ch_1] += 1;
        data[ch_2] -= 1;
        move.push_back(ch_1);
      } else {
        data[ch_1] -= 1;
        data[ch_2] += 1;
        move.push_back(ch_2);
      }
    }
    if (data['A'] < 0 || data['B'] < 0 || data['C'] < 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  char ch_1 = choices[n - 1][0];
  char ch_2 = choices[n - 1][1];
  if (data[ch_1] == 0) {
    data[ch_1] += 1;
    move.push_back(ch_1);
    data[ch_2] -= 1;
  } else {
    data[ch_2] += 1;
    move.push_back(ch_2);
    data[ch_1] -= 1;
  }
  if (data['A'] < 0 || data['B'] < 0 || data['C'] < 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for (auto x : move) {
    cout << x << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  ll data[3];
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  string choices[n];
  vector<char> move;

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

  for (int i = 0; i <= n - 1; i++) {
    int ch_1 = choices[i][0] - 'A';
    int ch_2 = choices[i][1] - 'A';
    if (data[ch_1] > data[ch_2]) {
      data[ch_1]--;
      data[ch_2]++;
      move.push_back(choices[i][1]);
    } else if (data[ch_1] < data[ch_2]) {
      data[ch_2]--;
      data[ch_1]++;
      move.push_back(choices[i][0]);
    } else {
      if (i < n - 1 && (choices[i][0] == choices[i + 1][0] ||
                        choices[i][0] == choices[i + 1][1])) {
        data[ch_1]++;
        data[ch_2]--;
        move.push_back(choices[i][0]);
      } else {
        data[ch_2]++;
        data[ch_1]--;
        move.push_back(choices[i][1]);
      }
    }
  }
  if (data[0] < 0 || data[1] < 0 || data[2] < 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  for (auto x : move) {
    cout << x << " ";
  }
  cout << endl;
  return 0;
}
Problem p02692 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  array<int, 3> a;
  for (auto &e : a)
    cin >> e;
  vector<string> s(n);
  for (auto &e : s)
    cin >> e;

  for (auto &e : a)
    e = min(e, 2);

  vector<char> r, t;
  vector<vector<vector<bool>>> v(n, vector<vector<bool>>(7, vector<bool>(7)));
  auto dfs = [&](auto &&dfs, int i) {
    if (i == n) {
      r = t;
      return;
    }
    if (v[i][a[0]][a[1]])
      return;
    v[i][a[0]][a[1]] = true;
    for (int k = 0; k < 2; k++) {
      int x = s[i][k] - 'A';
      int y = s[i][1 - k] - 'A';
      if (a[x] <= 0)
        continue;
      a[x]--;
      a[y]++;
      t.push_back('A' + y);
      dfs(dfs, i + 1);
      t.pop_back();
      a[x]++;
      a[y]--;
    }
  };
  dfs(dfs, 0);

  if (r.empty()) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (auto e : r)
      cout << e << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  array<int, 3> a;
  for (auto &e : a)
    cin >> e;
  vector<string> s(n);
  for (auto &e : s)
    cin >> e;

  for (auto &e : a)
    e = min(e, 3);

  vector<char> r, t;
  auto dfs = [&](auto &&dfs, int i) {
    if (i == n) {
      r = t;
      return;
    }
    for (int k = 0; k < 2; k++) {
      int x = s[i][k] - 'A';
      int y = s[i][1 - k] - 'A';
      if (a[x] <= 0)
        continue;
      a[x]--;
      a[y]++;
      t.push_back('A' + y);
      dfs(dfs, i + 1);
      t.pop_back();
      a[x]++;
      a[y]--;
    }
  };
  dfs(dfs, 0);

  if (r.empty()) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (auto e : r)
      cout << e << endl;
  }
}
Problem p02692 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {
} LOG;
template <typename T> DebugStream &operator<<(DebugStream &s, const T &) {
  return s;
}
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20,
          bs = 29;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  int n;
  cin >> n;
  map<char, int> mp;
  cin >> mp['A'] >> mp['B'] >> mp['C'];

  vector<string> vc(n);
  for (auto &el : vc)
    cin >> el;

  for (int i = 0; i < n; i++) {
    char &p = vc[i][0], &q = vc[i][1];
    if (mp[p] > mp[q] ||
        (mp[p] == mp[q] && (i + 1 == n || vc[i + 1].find(q) != string::npos)))
      swap(p, q);
    mp[p]++, mp[q]--;
    if (mp[q] < 0) {
      cout << "No\\n";
      return 0;
    }
  }

  cout << "Yes\\n";
  for (auto el : vc)
    cout << el[0] << '\\n';
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {
} LOG;
template <typename T> DebugStream &operator<<(DebugStream &s, const T &) {
  return s;
}
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20,
          bs = 29;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  int n;
  cin >> n;
  map<char, int> mp;
  cin >> mp['A'] >> mp['B'] >> mp['C'];

  vector<string> vc(n);
  for (auto &el : vc)
    cin >> el;

  for (int i = 0; i < n; i++) {
    char &p = vc[i][0], &q = vc[i][1];
    if (mp[p] > mp[q] ||
        (mp[p] == mp[q] && (i == n || vc[i + 1].find(q) != string::npos)))
      swap(p, q);
    mp[p]++, mp[q]--;
    if (mp[q] < 0) {
      cout << "No\\n";
      return 0;
    }
  }

  cout << "Yes\\n";
  for (auto el : vc)
    cout << el[0] << '\\n';
}
Problem p02692 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
const int N = 100005;

int n, a, b, c;

vector<string> v;
bool ans[N];
void dfs(int idx, int a, int b, int c) {
  if (a < 0 or b < 0 or c < 0)
    return;

  if (idx >= n) {
    cout << "Yes" << endl;

    for (int i = 0; i < n; i++) {
      cout << v[i][ans[i]] << endl;
    }
    exit(0);
    return;
  }

  int a1 = a, b1 = b, c1 = c;

  if (v[idx][0] == 'A')
    a++;
  if (v[idx][0] == 'B')
    b++;
  if (v[idx][0] == 'C')
    c++;
  if (v[idx][1] == 'A')
    a--;
  if (v[idx][1] == 'B')
    b--;
  if (v[idx][1] == 'C')
    c--;

  ans[idx] = 0;
  if (a >= 0 and b >= 0 and c >= 0)
    dfs(idx + 1, a, b, c);

  a = a1;
  b = b1;
  c = c1;

  if (v[idx][0] == 'A')
    a--;
  if (v[idx][0] == 'B')
    b--;
  if (v[idx][0] == 'C')
    c--;
  if (v[idx][1] == 'A')
    a++;
  if (v[idx][1] == 'B')
    b++;
  if (v[idx][1] == 'C')
    c++;

  ans[idx] = 1;
  if (a >= 0 and b >= 0 and c >= 0)
    dfs(idx + 1, a, b, c);
}

int32_t main() {

  IOS

          cin >>
      n >> a >> b >> c;

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

    v.push_back(s);
  }

  dfs(0, a, b, c);

  cout << "No";

  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
const int N = 100005;

int n, a, b, c;

vector<string> v;

void dfs(int idx, int a, int b, int c, vector<bool> ans) {
  if (a < 0 or b < 0 or c < 0)
    return;

  if (idx >= n) {
    cout << "Yes" << endl;

    for (int i = 0; i < ans.size(); i++) {
      cout << v[i][ans[i]] << endl;
    }
    exit(0);
    return;
  }

  int a1 = a, b1 = b, c1 = c;

  if (v[idx][0] == 'A')
    a++;
  if (v[idx][0] == 'B')
    b++;
  if (v[idx][0] == 'C')
    c++;
  if (v[idx][1] == 'A')
    a--;
  if (v[idx][1] == 'B')
    b--;
  if (v[idx][1] == 'C')
    c--;

  ans[idx] = 0;
  if (a >= 0 and b >= 0 and c >= 0)
    dfs(idx + 1, a, b, c, ans);

  a = a1;
  b = b1;
  c = c1;

  if (v[idx][0] == 'A')
    a--;
  if (v[idx][0] == 'B')
    b--;
  if (v[idx][0] == 'C')
    c--;
  if (v[idx][1] == 'A')
    a++;
  if (v[idx][1] == 'B')
    b++;
  if (v[idx][1] == 'C')
    c++;

  ans[idx] = 1;
  if (a >= 0 and b >= 0 and c >= 0)
    dfs(idx + 1, a, b, c, ans);
}

int32_t main() {

  IOS

          cin >>
      n >> a >> b >> c;

  vector<bool> ans(n);

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

    v.push_back(s);
  }

  dfs(0, a, b, c, ans);

  cout << "No";

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

#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

void No() {
  cout << "No\\n";
  exit(0);
}

int main() {
  int N;
  cin >> N;
  vector<int> num(3);
  for (int i = 0; i < 3; ++i) {
    cin >> num[i];
  }
  vector<string> s(N);
  for (int i = 0; i < N; ++i) {
    cin >> s[i];
  }

  auto wl = [&](int x, int y) {
    ++num[x];
    --num[y];
  };

  string ABC = "ABC";
  string ans = "";
  for (int i = 0; i < N; ++i) {
    for (int v : num) {
      if (v < 0) {
        No();
      }
    }

    int c0 = s[i][0] - 'A', c1 = s[i][1] - 'A';
    if (num[c0] == 0 && num[c1] == 0) {
      No();
    }

    if (num[c0] != num[c1] || i == N - 1) {
      if (num[c0] > num[c1]) {
        wl(c1, c0);
        ans += ABC[c1];
      } else {
        wl(c0, c1);
        ans += ABC[c0];
      }
      continue;
    }

    bool add0 = false;
    for (auto c : s[i + 1]) {
      add0 = add0 || (c == s[i][0]);
    }
    if (add0) {
      wl(c0, c1);
      ans += ABC[c0];
    } else {
      wl(c1, c0);
      ans += ABC[c1];
    }
  }

  cout << "Yes\\n";
  for (auto c : ans) {
    cout << c << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int N;
vector<int> num(3), ans;
vector<string> s(100010);
bool ok = true;

bool tapi(int i0, int i1) {
  ++num[i0];
  --num[i1];
  return num[i0] >= 0 && num[i1] >= 0;
}

void tapu(int idx) {
  if (!ok || ans.size() == N) {
    return;
  }
  int c0 = s[idx][0] - 'A', c1 = s[idx][1] - 'A';
  if (num[c0] >= num[c1]) {
    if (tapi(c1, c0)) {
      ans.emplace_back(1);
      tapu(idx + 1);
      if (ans.size() == N) {
        return;
      }
    }
    tapi(c0, c1);
    ans.pop_back();
  }
  if (num[c0] <= num[c1]) {
    if (tapi(c0, c1)) {
      ans.emplace_back(0);
      tapu(idx + 1);
      if (ans.size() == N) {
        return;
      }
    }
    tapi(c1, c0);
    ans.pop_back();
  }
  ok = false;
}

int main() {
  cin >> N;
  for (int i = 0; i < 3; ++i) {
    cin >> num[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> s[i];
  }

  tapu(0);
  if (ok) {
    cout << "Yes\\n";
    for (int i = 0; i < N; ++i) {
      cout << s[i][ans[i]] << endl;
    }
  } else {
    cout << "No\\n";
  }

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

#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#define N 100020
using namespace std;

char a[N][3];
char o[N];

int main(void) {
  int n, v[3];
  int i;

  scanf("%d %d %d %d", &n, &v[0], &v[1], &v[2]);
  for (i = 0; i < n; i++) {
    scanf("%s", a[i]);
    a[i][0] -= 65;
    a[i][1] -= 65;
  }

  for (i = 0; i < n; i++)
    if (v[a[i][0]] < v[a[i][1]]) {
      o[i] = a[i][0] + 65;
      v[a[i][0]]++;
      v[a[i][1]]--;
    } else if (v[a[i][0]] > v[a[i][1]]) {
      o[i] = a[i][1] + 65;
      v[a[i][1]]++;
      v[a[i][0]]--;
    } else {
      if (!v[a[i][0]]) {
        printf("No\\n");
        break;
      }
      if (i < n - 1 && ((a[i][0] == a[i + 1][0] && a[i][1] != a[i + 1][1]) ||
                        (a[i][0] == a[i + 1][1] && a[i][1] != a[i + 1][0]))) {
        o[i] = a[i][0] + 65;
        v[a[i][0]]++;
        v[a[i][1]]--;
      } else {
        o[i] = a[i][1] + 65;
        v[a[i][1]]++;
        v[a[i][0]]--;
      }
    }

  if (i == n) {
    printf("Yes\\n");
    for (i = 0; i < n; i++)
      printf("%c\\n", o[i]);
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>

const int MAXN = 100010;
int n, r, v[3], s[MAXN], q[MAXN], mask;
char tmp[MAXN][5], ans[MAXN];

const int remap[7][2] = {
    {-1, -1}, {0, -1}, {1, -1}, {0, 1}, {2, -1}, {0, 2}, {1, 2},
};

void set(const int x) {
  int y = 1 << x;
  while (r) {
    r--;
    ans[q[r]] = 'A' + remap[y][0];
    v[remap[y][0]]++;
    y ^= s[q[r]];
    v[remap[y][0]]--;
  }
}

void check(const int x) {
  if (v[x] == 0 && (mask ^ (1 << x)) != 0)
    set(x);
}

int main() {
  scanf("%d %d %d %d", &n, &v[0], &v[1], &v[2]);
  for (int i = 1; i <= n; i++) {
    scanf("%s", tmp[i]);
    s[i] ^= 1 << (tmp[i][0] - 'A');
    s[i] ^= 1 << (tmp[i][1] - 'A');
  }

  for (int i = 1; i <= n; i++) {
    const int *p = remap[s[i]];
    if (v[p[0]] == v[p[1]] && v[p[0]] == 1) {
      if (s[i] ^ mask) {
        q[r++] = i;
        mask ^= s[i];
      } else {
        ans[i] = 'A' + p[0];
        v[p[0]]++;
        v[p[1]]--;
        set(p[1]);
        mask = 0;
      }
    } else if (v[p[0]] > v[p[1]]) {
      v[p[0]]--;
      v[p[1]]++;
      ans[i] = 'A' + p[1];
      check(p[0]);
    } else {
      v[p[0]]++;
      v[p[1]]--;
      if (v[p[1]] < 0) {
        puts("No");
        return 0;
      }
      ans[i] = 'A' + p[0];
      check(p[1]);
    }
  }

  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%c\\n", ans[i]);

  return 0;
}