Language: C++

#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	
	vector<string> s(n), ans(n);
	for(int i = 0; i < n; i++) cin >> s[i];
		
	if((a + b + c) == 2) {
		if(s[0] == "AB" && a == 0 && b == 0) ok = 0;
		if(s[1] == "BC" && c == 0 && b == 0) ok = 0;
		if(s[2] == "AC" && a == 0 && c == 0) ok = 0;
		
		for(int i = 0; i < n && ok; i++) {
			if(s[i] == "AB") {
				if(a == b && b == 1) {
					if(i == n - 1 || s[i + 1] == s[i]) {
						ans[i] = "A";
						a++;
						b--;
					} else if(s[i + 1] == "BC") {
						b++;
						a--;
						ans[i] = "B";
					} else {
						a++;
						c--;
						ans[i] = "A";
					}
					
					continue;
				}
				
				if(a > b) {
					a--;
					b++;
					ans[i] = "B";
				} else {	
					a++;
					b--;
					ans[i] = "A";
				}
			} else if(s[i] == "BC") {
				if(c == b && b == 1) {
					if(i == n - 1 || s[i + 1] == s[i]) {
						ans[i] = "B";
						b++;
						c--;
					} else if(s[i + 1] == "AB") {
						b++;
						c--;
						ans[i] = "B";
					} else {
						c++;
						b--;
						ans[i] = "C";
					}
					
					continue;
				}
				
				if(b > c) {
					b--;
					c++;
					ans[i] = "C";
				} else {
					b++;
					c--;
					ans[i] = "B";
				}
			} else {
				if(c == a && a == 1) {
					if(i == n - 1 || s[i + 1] == s[i]) {
						ans[i] = "A";
						a++;
						c--;
					} else if(s[i + 1] == "AB") {
						a++;
						c--;
						ans[i] = "A";
					} else {
						c++;
						a--;
						ans[i] = "C";
					}
					
					continue;
				}
				
				if(a > c) {
					a--;
					c++;
					ans[i] = "C";
				} else {
					a++;
					c--;
					ans[i] = "A";
				}
			}
		}
		
		cout << (ok ? "Yes" : "No") << endl;
		for(int i = 0; i < n && ok; i++) {
			cout << ans[i] << endl;
		}
	} else {
		int ok = 1;
		for(int i = 0; i < n && ok; i++) {
			if(s[i] == "AB") {
				if(a == b && b == 0) ok = 0;
				if(a > b) {
					a--;
					b++;
					ans[i] = "B";
				} else {
					a++;
					b--;
					ans[i] = "A";
				}
			} else if(s[i] == "BC") {
				if(b == c && c == 0) ok = 0;
				if(b > c) {
					b--;
					c++;
					ans[i] = "C";
				} else {
					b++;
					c--;
					ans[i] = "B";
				}
			} else {
				if(a == c && c == 0) ok = 0;
				if(a > c) {
					a--;
					c++;
					ans[i] = "C";
				} else {
					a++;
					c--;
					ans[i] = "A";
				}
			}
		}
		
		cout << (ok ? "Yes" : "No") << endl;
		for(int i = 0; i < n && ok; i++) {
			cout << ans[i] << endl;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:30:54: error: 'ok' was not declared in this scope
   30 |                 if(s[0] == "AB" && a == 0 && b == 0) ok = 0;
      |                                                      ^~
a.cc:31:54: error: 'ok' was not declared in this scope
   31 |                 if(s[1] == "BC" && c == 0 && b == 0) ok = 0;
      |                                                      ^~
a.cc:32:54: error: 'ok' was not declared in this scope
   32 |                 if(s[2] == "AC" && a == 0 && c == 0) ok = 0;
      |                                                      ^~
a.cc:34:41: error: 'ok' was not declared in this scope
   34 |                 for(int i = 0; i < n && ok; i++) {
      |                                         ^~
a.cc:122:26: error: 'ok' was not declared in this scope
  122 |                 cout << (ok ? "Yes" : "No") << endl;
      |                          ^~