Language: C++

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 200001;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

string s;
string ss[N];

const int mx = 20;

bool dp[N][mx][mx][mx];
char pp[N][mx][mx][mx];
char lp[N][mx][mx][mx];

int v1, v2;

void solve(){
    int n, a, b, c; cin>>n>>a>>b>>c;
    if(a > mx-1)
        a = mx-1;
    if(b > mx-1)
        b = mx-1;
    if(c > mx-1)
        c = mx-1;
    dp[0][a][b][c]=true;
    vector<char> ans;
    For(i, 0, n){
        cin>>s;
        ss[i]=s;
        For(j, 0, mx){
            For(k, 0, mx){
                For(l, 0, mx){
                    if(!dp[i][j][k][l])
                        continue;
                    // trace(i, j, k, l);
                    if(s[0]=='A' && s[1]=='B'){
                        v1 = j-1;
                        v2 = min(k+1, mx-1);
                        if(v1 >= 0){
                            dp[i+1][v1][v2][l]=true;
                            pp[i+1][v1][v2][l]='B';
                            lp[i+1][v1][v2][l]='A';
                        }
                        v1 = min(j+1, mx-1);
                        v2 = k-1;
                        if(v2 >= 0){
                            dp[i+1][v1][v2][l]=true;
                            pp[i+1][v1][v2][l]='A';
                            lp[i+1][v1][v2][l]='B';
                        }
                    }
                    if(s[0]=='A' && s[1]=='C'){
                        v1 = j-1;
                        v2 = min(l+1, mx-1);
                        if(v1 >= 0){
                            dp[i+1][v1][k][v2]=true;
                            pp[i+1][v1][k][v2]='C';
                            lp[i+1][v1][k][v2]='A';
                        }
                        v1 = min(j+1, mx-1);
                        v2 = l-1;
                        if(v2 >= 0){
                            dp[i+1][v1][k][v2]=true;
                            pp[i+1][v1][k][v2]='A';
                            lp[i+1][v1][k][v2]='C';
                        }
                    }
                    if(s[0]=='B' && s[1]=='C'){
                        v1 = k-1;
                        v2 = min(l+1, mx-1);
                        if(v1 >= 0){
                            dp[i+1][j][v1][v2]=true;
                            pp[i+1][j][v1][v2]='C';
                            lp[i+1][j][v1][v2]='B';
                        }
                        v1 = min(k+1, mx-1);
                        v2 = l-1;
                        if(v2 >= 0){
                            dp[i+1][j][v1][v2]=true;
                            pp[i+1][j][v1][v2]='B';
                            lp[i+1][j][v1][v2]='C';
                        }
                    }
                }
            }
        }
    }
    int cur[3];
    memset(cur, -1, sizeof(cur));
    For(i, 0, mx){
        For(j, 0, mx){
            For(k, 0, mx){
                if(dp[n][i][j][k]){
                    cur[0]=i;
                    cur[1]=j;
                    cur[2]=k;
                }
            }
        }
    }
    if(cur[0]==-1){
        cout<<"No";
        return;
    }
    cout<<"Yes\n";

    for(int i=n; i>0; i--){
        ans.pb(pp[i][cur[0]][cur[1]][cur[2]]);
        int ap = pp[i][cur[0]][cur[1]][cur[2]]-'A';
        int sp = lp[i][cur[0]][cur[1]][cur[2]]-'A';
        cur[ap]--;
        cur[sp]++;
    }
    reverse(all(ans));
    for(char x: ans){
        cout<<x<<"\n";
    }
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}





Compiler output:
/tmp/ccBKbAaa.o: in function `solve()':
a.cc:(.text+0x241): relocation truncated to fit: R_X86_64_PC32 against symbol `v1' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x27e): relocation truncated to fit: R_X86_64_PC32 against symbol `v2' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x285): relocation truncated to fit: R_X86_64_PC32 against symbol `v1' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x29d): relocation truncated to fit: R_X86_64_PC32 against symbol `v1' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `v2' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x302): relocation truncated to fit: R_X86_64_PC32 against symbol `v1' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x309): relocation truncated to fit: R_X86_64_PC32 against symbol `v2' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x367): relocation truncated to fit: R_X86_64_PC32 against symbol `v1' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x36e): relocation truncated to fit: R_X86_64_PC32 against symbol `v2' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x3b7): relocation truncated to fit: R_X86_64_PC32 against symbol `lp' defined in .bss section in /tmp/ccBKbAaa.o
a.cc:(.text+0x3fa): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status