Language: C++

/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

vector<string> queries = {"AB", "AC", "BC"};

bool exist(string &s, char cc) {
	return s[0] != cc && s[1] != cc;
}

char other(string &s, char cc) {
	return s[0] != cc ? s[0] : s[1];
}

string getRequest(char cc) {
	for (string &tmp: queries) {
		if (!exist(tmp, cc)) {
			return tmp;
		}
	}
	return "";
}

char another(char a, char b) {
	for (char cc = 'A'; cc <= 'C'; ++cc) {
		if (cc != a && cc != b) return cc;
	}
	return 'a';
}

map<char, map<string, set<int>>> eq;
map<char, map<string, set<int>>> pendingReplace;

int main() {
	int N;
	map<char, int> val, awal;
	sci(N), sci(val['A']), sci(val['B']), sci(val['C']);
	awal['A'] = val['A'];
	awal['B'] = val['B'];
	awal['C'] = val['C'];
	string s[N];
	for (int i = 0; i < N; ++i) {
		cin >> s[i];
	}
	string ans;
	ans.resize(N);
	for (int i = 0; i < N; ++i) {
		if (val[s[i][0]] > val[s[i][1]]) {
			ans[i] = s[i][1];
			--val[s[i][0]];
			++val[s[i][1]];
		} else if (val[s[i][0]] < val[s[i][1]]) {
			ans[i] = s[i][0];
			--val[s[i][1]];
			++val[s[i][0]];
		} else {
			if (val[s[i][0]] == 0) {
				if (!exist(s[i], 'A')) {
					bool found = 0;
					for (string &tmp : queries) {
						if (!exist(tmp, 'A')) continue;
						if (!eq['A'][tmp].empty()) {
							auto it = eq['A'][tmp].begin();
							ans[*it] = other(tmp, 'A');
							val['A'] -= 2; val['B'] += 1; val['C'] += 1;
							pendingReplace['A'][tmp].insert(*it);
							eq['A'][tmp].erase(it);
							found = 1;
							ans[i] = another(ans[*it], 'A');
							break;
						}
					}
					if (found && val['A'] >= 0) continue;
					puts("No");
					return 0;
				} else if (!exist(s[i], 'B')) {
					bool found = 0;
					for (string &tmp : queries) {
						if (!exist(tmp, 'B')) continue;
						if (!eq['B'][tmp].empty()) {
							auto it = eq['B'][tmp].begin();
							ans[*it] = other(tmp, 'B');
							val['B'] -= 2; ++val['A']; ++val['C'];
							pendingReplace['B'][tmp].insert(*it);
							eq['B'][tmp].erase(it);
							found = 1;
							ans[i] = another(ans[*it], 'B');
							break;
						}
					}
					if (found && && val['B'] >= 0) continue;
					puts("No");
					return 0;
				} else {
					bool found = 0;
					for (string &tmp : queries) {
						if (!exist(tmp, 'C')) continue;
						if (!eq['C'][tmp].empty()) {
							auto it = eq['C'][tmp].begin();
							ans[*it] = other(tmp, 'C');
							val['C'] -= 2; ++val['A']; ++val['B'];
							pendingReplace['C'][tmp].insert(*it);
							eq['C'][tmp].erase(it);
							found = 1;
							ans[i] = another(ans[*it], 'C');
							break;
						}
					}
					if (found && val['C'] >= 0) continue;
					puts("No");
					return 0;
				}
			} else {
				ans[i] = s[i][0];
				++val[s[i][0]];
				--val[s[i][1]];
				eq[s[i][0]][s[i]].insert(i);
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		char add = ans[i];
		char sub = other(s[i], ans[i]);
		++val[add];
		--val[sub];
		assert(add >= 0);
		assert(sub >= 0);
	}
	puts("Yes");
	for (char &cc : ans) {
		cout << cc << '\n';
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:142:60: error: expected ')' before '[' token
  142 |                                         if (found && && val['B'] >= 0) continue;
      |                                            ~               ^
      |                                                            )
a.cc:142:57: error: label 'val' used but not defined
  142 |                                         if (found && && val['B'] >= 0) continue;
      |                                                         ^~~