Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.

int main()
{
	int n,a,b,c;cin>>n>>a>>b>>c;
	for(int i=1;i<=n;i++)
	    cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		if(s[i]=="AB"){
			if(a==0&&b==0){
				cout<<"NO";
				return 0;
			}
			if(a>b)a--,b++,ans[i]='B';
			else if(a<b)a++,b--,ans[i]='A';
			else{
				if(s[i+1]=="BC")a--,b++,ans[i]='B';
				else a++,b--,ans[i]='A';
			}
		}
		if(s[i]=="BC"){
			if(c==0&&b==0){
				cout<<NO;
				return 0;
			}
			if(c>b)c--,b++,ans[i]='B';
			else if(c<b)c++,b--,ans[i]='C';
			else{
				if(s[i+1]=="AB")c--,b++,ans[i]='B';
				else c++,b--,ans[i]='C';
			}
		}
		if(s[i]=="AC"){
			if(a==0&&c==0){
				cout<<No;
				return 0;
			}
			if(a>c)a--,c++,ans[i]='C';
			else if(a<c)a++,c--,ans[i]='A';
			else{
				if(s[i+1]=="BC")a--,c++,ans[i]='C';
				else a++,c--,ans[i]='A';
			}
		}
	}
	cout<<Yes;;
	for(int i=1;i<=n;i++)
	printf("%c\n",ans[i]);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:18: error: 's' was not declared in this scope
   11 |             cin>>s[i];
      |                  ^
a.cc:14:20: error: 's' was not declared in this scope
   14 |                 if(s[i]=="AB"){
      |                    ^
a.cc:19:40: error: 'ans' was not declared in this scope; did you mean 'abs'?
   19 |                         if(a>b)a--,b++,ans[i]='B';
      |                                        ^~~
      |                                        abs
a.cc:20:45: error: 'ans' was not declared in this scope; did you mean 'abs'?
   20 |                         else if(a<b)a++,b--,ans[i]='A';
      |                                             ^~~
      |                                             abs
a.cc:22:57: error: 'ans' was not declared in this scope; did you mean 'abs'?
   22 |                                 if(s[i+1]=="BC")a--,b++,ans[i]='B';
      |                                                         ^~~
      |                                                         abs
a.cc:23:46: error: 'ans' was not declared in this scope; did you mean 'abs'?
   23 |                                 else a++,b--,ans[i]='A';
      |                                              ^~~
      |                                              abs
a.cc:26:20: error: 's' was not declared in this scope
   26 |                 if(s[i]=="BC"){
      |                    ^
a.cc:28:39: error: 'NO' was not declared in this scope
   28 |                                 cout<<NO;
      |                                       ^~
a.cc:31:40: error: 'ans' was not declared in this scope; did you mean 'abs'?
   31 |                         if(c>b)c--,b++,ans[i]='B';
      |                                        ^~~
      |                                        abs
a.cc:32:45: error: 'ans' was not declared in this scope; did you mean 'abs'?
   32 |                         else if(c<b)c++,b--,ans[i]='C';
      |                                             ^~~
      |                                             abs
a.cc:34:57: error: 'ans' was not declared in this scope; did you mean 'abs'?
   34 |                                 if(s[i+1]=="AB")c--,b++,ans[i]='B';
      |                                                         ^~~
      |                                                         abs
a.cc:35:46: error: 'ans' was not declared in this scope; did you mean 'abs'?
   35 |                                 else c++,b--,ans[i]='C';
      |                                              ^~~
      |                                              abs
a.cc:38:20: error: 's' was not declared in this scope
   38 |                 if(s[i]=="AC"){
      |                    ^
a.cc:40:39: error: 'No' was not declared in this scope
   40 |                                 cout<<No;
      |                                       ^~
a.cc:43:40: error: 'ans' was not declared in this scope; did you mean 'abs'?
   43 |                         if(a>c)a--,c++,ans[i]='C';
      |                                        ^~~
      |                                        abs
a.cc:44:45: error: 'ans' was not declared in this scope; did you mean 'abs'?
   44 |                         else if(a<c)a++,c--,ans[i]='A';
      |                                             ^~~
      |                                             abs
a.cc:46:57: error: 'ans' was not declared in this scope; did you mean 'abs'?
   46 |                                 if(s[i+1]=="BC")a--,c++,ans[i]='C';
      |                                                         ^~~
      |                                                         abs
a.cc:47:46: error: 'ans' was not declared in this scope; did you mean 'abs'?
   47 |                                 else a++,c--,ans[i]='A';
      |                                              ^~~
      |                                              abs
a.cc:51:15: error: 'Yes' was not declared in this scope
   51 |         cout<<Yes;;
      |               ^~~
a.cc:53:23: error: 'ans' was not declared in this scope; did you mean 'abs'?
   53 |         printf("%c\n",ans[i]);
      |                       ^~~
      |                       abs