Language: C++

#include <bits/stdc++.h>
using namespace std;

int n, a, b, c, g[4];
string s;
vector<int> v, o[4];

void gk(int a, int b) {
	if(b == 1) {
		if(a == 1) {
			cout << "B\n";
		} else {
			cout << "A\n";
		}
	} else if(b == 2) {
		if(a == 1) {
			cout << "C\n";
		} else {
			cout << "B\n";
		}
	} else {
		if(a == 1) {
			cout << "C\n";
		} else {
			cout << "A\n";
		}
	}
}

void D(int x, int y, int z, int f) {
	cout << "Yes\n";
	if(f) {
		o[1].push_back(1);
		o[2].push_back(1);
		o[3].push_back(-1);
		--g[1];
		--g[2];
		--g[3];
	}
	if(x) o[1].push_back(x), --g[1];
	if(y) o[2].push_back(y), --g[2];
	if(z) o[3].push_back(z), --g[3];
	while(g[1]) {
		v[1].push_back(1);
		v[1].push_back(-1);
		g[1] -= 2;
	}
	while(g[2]) {
		v[2].push_back(1);
		v[2].push_back(-1);
		g[2] -= 2;
	}
	while(g[3]) {
		v[3].push_back(1);
		v[3].push_back(-1);
		g[3] -= 2;
	}
	assert(g[1] == 0 && g[2] == 0 && g[3] == 0);
	for(int i = 0; i < v.size(); ++i) {
		gk(o[v[i]][g[v[i]]], v[i]);
		++g[v[i]];
	}
	cout << flush;
	exit(0);
}

void G(int x, int y, int z, int f) {
	if(x + y + z == 3) return;
	if(x + y + z == 0) D(0, 0, 0, f);
	if(x + y + z == 1) {
		if(x) {
			if(a) {
				D(1, 0, 0, f);
			} else if(b) {
				D(-1, 0, 0, f);
			} else {
				return;
			}
		}
		if(y) {
			if(b) {
				D(0, 1, 0, f);
			} else if(c) {
				D(0, -1, 0, f);
			} else {
				return;
			}
		}
		if(z) {
			if(a) {
				D(0, 0, 1, f);
			} else if(c) {
				D(0, 0, -1, f);
			} else {
				return;
			}
		}
	}
	if(x + y + z == 2) {
		if(x + y == 2) {
			if(a && c) {
				D(1, -1, 0, f);
			} else if(!a && c) {
				D(-1, -1, 0, f);
			} else if(a && !c) {
				D(1, 1, 0, f);
			} else if(b >= 2) {
				D(-1, 1, 0, f);
			} else {
				return;
			}
		}
		if(y + z == 2) {
			if(a && b) {
				D(0, 1, 1, f);
			} else if(!a && b) {
				D(0, 1, -1, f);
			} else if(a && !b) {
				D(0, -1, 1, f);
			} else if(c >= 2) {
				D(0, -1, -1, f);
			} else {
				return;
			}
		}
		if(x + z == 2) {
			if(b && c) {
				D(-1, 0, -1, f);
			} else if(!b && c) {
				D(1, 0, -1, f);
			} else if(b && !c) {
				D(-1, 0, 1, f);
			} else if(a >= 2) {
				D(1, 0, 1, f);
			} else {
				return;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> a >> b >> c;
	for(int i = 1; i <= n; ++i) {
		cin >> s;
		int t = 3;
		if(s == "AB") t = 1;
		else if(s == "BC") t = 2;
		++g[t];
		v.push_back(t);
	}
	if(g[1] && g[2] && g[3]) G((g[1] & 1 ^ 1), (g[2] & 1 ^ 1), (g[3] & 1 ^ 1), 1);
	G((g[1] & 1), (g[2] & 1), (g[3] & 1), 0);
	cout << "No" << endl;
	return 0;
}


Compiler output:
a.cc: In function 'void D(int, int, int, int)':
a.cc:44:22: error: request for member 'push_back' in 'v.std::vector<int>::operator[](1)', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   44 |                 v[1].push_back(1);
      |                      ^~~~~~~~~
a.cc:45:22: error: request for member 'push_back' in 'v.std::vector<int>::operator[](1)', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   45 |                 v[1].push_back(-1);
      |                      ^~~~~~~~~
a.cc:49:22: error: request for member 'push_back' in 'v.std::vector<int>::operator[](2)', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   49 |                 v[2].push_back(1);
      |                      ^~~~~~~~~
a.cc:50:22: error: request for member 'push_back' in 'v.std::vector<int>::operator[](2)', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   50 |                 v[2].push_back(-1);
      |                      ^~~~~~~~~
a.cc:54:22: error: request for member 'push_back' in 'v.std::vector<int>::operator[](3)', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   54 |                 v[3].push_back(1);
      |                      ^~~~~~~~~
a.cc:55:22: error: request for member 'push_back' in 'v.std::vector<int>::operator[](3)', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   55 |                 v[3].push_back(-1);
      |                      ^~~~~~~~~