Language: C++

#include<bits/stdc++.h>
#define in inline
#define int long long
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int n,m,ans[100002],A,B,C,dp[100002][3][3][3],pre[100002][3][3][3];
char s[12];
long long sum;
inline void work(re int x,re int a,re int b,re int c){
	if(x==0)return;
	re int xx=pre[x][a][b][c];
	if(xx==1)++a,--b;
	if(xx==2)--a,++b;
	if(xx==3)++a,--c;
	if(xx==4)--a,++c;
	if(xx==5)++b,--c;
	if(xx==6)--b,++c;
	work(x-1,a,b,c);
	if(xx==2||xx==4)puts("A");
	if(xx==1||xx==6)puts("B");
	if(xx==3||xx==5)puts("C");
}
signed main(){
	n=read();A=read();B=read();C=read();
//	if(A+B+C==2ll)return 1;
	if(A+B+C!=2ll){
		for(re int i=1;i<=n;++i){
			scanf("%s",s+1);
			if(s[1]=='A'&&s[2]=='B'){
				if(A>B){--A;++B;ans[i]=2;
				}
				else{
					if(B==0){
						puts("No");
						return 0;
					}
					--B;++A;
					ans[i]=1;
				}
			}
			if(s[1]=='A'&&s[2]=='C'){
				if(A>C){
					--A;++C;
					ans[i]=3;
				}
				else{
					if(C==0){
						puts("No");
						return 0;
					}
					--C;++A;
					ans[i]=1;
				}
			}
			if(s[1]=='B'&&s[2]=='C'){
				if(B>C){
					--B;++C;
					ans[i]=3;
				}
				else{
					if(C==0){
						puts("No");
						return 0;
					}
					--C;++B;
					ans[i]=2;
				}
			}
		}
		puts("Yes");
		for(re int i=1;i<=n;++i){
			if(ans[i]==1)puts("A");
			if(ans[i]==2)puts("B");
			if(ans[i]==3)puts("C");
		}
	}
	else{
		dp[0][A][B][C]=1;
		for(re int ii=1;ii<=n;++ii){
			scanf("%s",s+1);
			if(s[1]=='A'&&s[2]=='B'){
				for(re int i=0;i<=1;++i){
					for(re int j=1;j<=2;++j){
						for(re int k=0;k<=2;++k){
							if(dp[ii-1][i+1][j-1][k]){
								dp[ii][i][j][k]=1;
								pre[ii][i][j][k]=1;
							}
						}
					}
				}
				for(re int i=1;i<=2;++i){
					for(re int j=0;j<=1;++j){
						for(re int k=0;k<=2;++k){
							if(dp[ii-1][i-1][j+1][k]){
								dp[ii][i][j][k]=1;
								pre[ii][i][j][k]=2;
							}
						}
					}
				}
			}
			if(s[1]=='A'&&s[2]=='C'){
				for(re int i=0;i<=1;++i){
					for(re int j=0;j<=2;++j){
						for(re int k=1;k<=2;++k){
							if(dp[ii-1][i+1][j][k-1]){
								dp[ii][i][j][k]=1;
								pre[ii][i][j][k]=3;
							}
						}
					}
				}
				for(re int i=1;i<=2;++i){
					for(re int j=0;j<=2;++j){
						for(re int k=0;k<=1;++k){
							if(dp[ii-1][i-1][j][k+1]){
								dp[ii][i][j][k]=1;
								pre[ii][i][j][k]=4;
							}
						}
					}
				}
			}
			if(s[1]=='B'&&s[2]=='C'){
				for(re int i=0;i<=2;++i){
					for(re int j=0;j<=1;++j){
						for(re int k=1;k<=2;++k){
							if(dp[ii-1][i][j+1][k-1]){
								dp[ii][i][j][k]=1;
								pre[ii][i][j][k]=5;
							}
						}
					}}
				for(re int i=0;i<=2;++i){
					for(re int j=1;j<=2;++j){
						for(re int k=0;k<=1;++k){
							if(dp[ii-1][i][j-1][k+1]){
								dp[ii][i][j][k]=1;
								pre[ii][i][j][k]=6;
							}
						}
					}
				}
			}
		}
		}
		for(re int i=0;i<=2;++i){
			for(re int j=0;j<=2;++j){
				for(re int k=0;k<=2;++k){
					if(dp[n][i][j][k]){
						puts("Yes");
						work(n,i,j,k);
						return 0;
					}
				}
			}
		}
		puts("No");
	}
}

Compiler output:
a.cc: In function 'long long int read()':
a.cc:7:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    7 |         re int t=0;
      |                ^
a.cc:8:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    8 |         re char v=getchar();
      |                 ^
a.cc: At global scope:
a.cc:19:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 | inline void work(re int x,re int a,re int b,re int c){
      |                         ^
a.cc:19:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 | inline void work(re int x,re int a,re int b,re int c){
      |                                  ^
a.cc:19:43: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 | inline void work(re int x,re int a,re int b,re int c){
      |                                           ^
a.cc:19:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   19 | inline void work(re int x,re int a,re int b,re int c){
      |                                                    ^
a.cc: In function 'void work(long long int, long long int, long long int, long long int)':
a.cc:21:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   21 |         re int xx=pre[x][a][b][c];
      |                ^~
a.cc: In function 'int main()':
a.cc:37:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |                 for(re int i=1;i<=n;++i){
      |                            ^
a.cc:81:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   81 |                 for(re int i=1;i<=n;++i){
      |                            ^
a.cc:89:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   89 |                 for(re int ii=1;ii<=n;++ii){
      |                            ^~
a.cc:92:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   92 |                                 for(re int i=0;i<=1;++i){
      |                                            ^
a.cc:93:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   93 |                                         for(re int j=1;j<=2;++j){
      |                                                    ^
a.cc:94:60: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   94 |                                                 for(re int k=0;k<=2;++k){
      |                                                            ^
a.cc:102:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  102 |                                 for(re int i=1;i<=2;++i){
      |                                            ^
a.cc:103:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  103 |                                         for(re int j=0;j<=1;++j){
      |                                                    ^
a.cc:104:60: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  104 |                                                 for(re int k=0;k<=2;++k){
      |                                                            ^
a.cc:114:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  114 |                                 for(re int i=0;i<=1;++i){
      |                                            ^
a.cc:115:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  115 |                                         for(re int j=0;j<=2;++j){
      |                                                    ^
a.cc:116:60: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  116 |                                                 for(re int k=1;k<=2;++k){
      |                                                            ^
a.cc:124:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  124 |                                 for(re int i=1;i<=2;++i){
      |                                            ^
a.cc:125:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  125 |                                         for(re int j=0;j<=2;++j){
      |                                                    ^
a.cc:126:60: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  126 |                                                 for(re int k=0;k<=1;++k){
      |                                                            ^
a.cc:136:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  136 |                                 for(re int i=0;i<=2;++i){
      |                                            ^
a.cc:137:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  137 |                                         for(re int j=0;j<=1;++j){
      |                                                    ^
a.cc:138:60: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  138 |                                                 for(re int k=1;k<=2;++k){
      |                                                            ^
a.cc:145:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  145 |                                 for(re int i=0;i<=2;++i){
      |                                            ^
a.cc:146:52: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  146 |                                         for(re int j=1;j<=2;++j){
      |                                                    ^
a.cc:147:60: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  147 |                                                 for(re int k=0;k<=1;++k){
      |                                                            ^
a.cc:158:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  158 |                 for(re int i=0;i<=2;++i){
      |                            ^
a.cc:159:36: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  159 |                         for(re int j=0;j<=2;++j){
      |                                    ^
a.cc:160:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  160 |                                 for(re int k=0;k<=2;++k){
      |                                            ^
a.cc: At global scope:
a.cc:171:1: error: expected declaration before '}' token
  171 | }
      | ^