Language: C++

//https://www.hamayanhamayan.com/entry/2020/05/03/224516
int N, A, B, C;
string S[101010];
//---------------------------------------------------------------------------------------------------
vector<char> ans;
bool dfs(int cu, int a, int b, int c) {
    if (cu == N) return true;

    if (S[cu] == "AB") {
        if (a == 0 && b == 0) return false;
        if (0 < a && dfs(cu + 1, a - 1, b + 1, c)) {
            ans.push_back('B');
            return true;
        }
        if (0 < b && dfs(cu + 1, a + 1, b - 1, c)) {
            ans.push_back('A');
            return true;
        }
        return false;
    }

    if (S[cu] == "AC") {
        if (a == 0 && c == 0) return false;
        if (0 < a && dfs(cu + 1, a - 1, b, c + 1)) {
            ans.push_back('C');
            return true;
        }
        if (0 < c && dfs(cu + 1, a + 1, b, c - 1)) {
            ans.push_back('A');
            return true;
        }
        return false;
    }

    if (S[cu] == "BC") {
        if (b == 0 && c == 0) return false;
        if (0 < b && dfs(cu + 1, a, b - 1, c + 1)) {
            ans.push_back('C');
            return true;
        }
        if (0 < c && dfs(cu + 1, a, b + 1, c - 1)) {
            ans.push_back('B');
            return true;
        }
        return false;
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> A >> B >> C;
    rep(i, 0, N) cin >> S[i];

    dfs(0, A, B, C);

    if (ans.size() == 0) cout << "No" << endl;
    else {
        printf("Yes\n");
        reverse(all(ans));
        fore(c, ans) printf("%c\n", c);
    }
}

Compiler output:
a.cc:3:1: error: 'string' does not name a type
    3 | string S[101010];
      | ^~~~~~
a.cc:5:1: error: 'vector' does not name a type
    5 | vector<char> ans;
      | ^~~~~~
a.cc: In function 'bool dfs(int, int, int, int)':
a.cc:9:9: error: 'S' was not declared in this scope
    9 |     if (S[cu] == "AB") {
      |         ^
a.cc:12:13: error: 'ans' was not declared in this scope
   12 |             ans.push_back('B');
      |             ^~~
a.cc:16:13: error: 'ans' was not declared in this scope
   16 |             ans.push_back('A');
      |             ^~~
a.cc:22:9: error: 'S' was not declared in this scope
   22 |     if (S[cu] == "AC") {
      |         ^
a.cc:25:13: error: 'ans' was not declared in this scope
   25 |             ans.push_back('C');
      |             ^~~
a.cc:29:13: error: 'ans' was not declared in this scope
   29 |             ans.push_back('A');
      |             ^~~
a.cc:35:9: error: 'S' was not declared in this scope
   35 |     if (S[cu] == "BC") {
      |         ^
a.cc:38:13: error: 'ans' was not declared in this scope
   38 |             ans.push_back('C');
      |             ^~~
a.cc:42:13: error: 'ans' was not declared in this scope
   42 |             ans.push_back('B');
      |             ^~~
a.cc: In function 'void _main()':
a.cc:50:5: error: 'cin' was not declared in this scope
   50 |     cin >> N >> A >> B >> C;
      |     ^~~
a.cc:51:9: error: 'i' was not declared in this scope
   51 |     rep(i, 0, N) cin >> S[i];
      |         ^
a.cc:51:5: error: 'rep' was not declared in this scope
   51 |     rep(i, 0, N) cin >> S[i];
      |     ^~~
a.cc:55:9: error: 'ans' was not declared in this scope
   55 |     if (ans.size() == 0) cout << "No" << endl;
      |         ^~~
a.cc:55:26: error: 'cout' was not declared in this scope
   55 |     if (ans.size() == 0) cout << "No" << endl;
      |                          ^~~~
a.cc:55:42: error: 'endl' was not declared in this scope
   55 |     if (ans.size() == 0) cout << "No" << endl;
      |                                          ^~~~
a.cc:57:9: error: 'printf' was not declared in this scope
   57 |         printf("Yes\n");
      |         ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | //https://www.hamayanhamayan.com/entry/2020/05/03/224516
a.cc:58:17: error: 'all' was not declared in this scope
   58 |         reverse(all(ans));
      |                 ^~~
a.cc:58:9: error: 'reverse' was not declared in this scope
   58 |         reverse(all(ans));
      |         ^~~~~~~
a.cc:59:14: error: 'c' was not declared in this scope
   59 |         fore(c, ans) printf("%c\n", c);
      |              ^
a.cc:59:9: error: 'fore' was not declared in this scope
   59 |         fore(c, ans) printf("%c\n", c);
      |         ^~~~
a.cc: In function 'bool dfs(int, int, int, int)':
a.cc:47:1: warning: control reaches end of non-void function [-Wreturn-type]
   47 | }
      | ^