Language: C++

/*author : Yashvardhan
Sunday, May 03, 2020
6:19 PM
*/

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

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}

int a,b,c;
vector<char> ans;

void doMove(int x){
	if(x == 1){
		if(a < b){
			a++; b--;
			ans.pb('A');
		}
		else{
			a--; b++;
			ans.pb('B');
		}
	}
	else if(x == 2){
		if(a < c){
			a++; c--;
			ans.pb('A');
		}
		else{
			a--; c++;
			ans.pb('C');
		}
	}
	else if(x == 3){
		if(b < c){
			b++; c--;
			ans.pb('B');
		}
		else{
			b--; c++;
			ans.pb('C');
		}
	}
}

bool checker(int x){
	if(x == 1){
		if(!(a == 0 || b == 0)) return true;
	}
	else if(x == 2){
		if(!(a == 0 || c == 0)) return true;
	}
	else if(x == 3){
		if(!(b == 0 || c == 0)) return true;
	}
	return false;
}

char first;
char second;
void setFirst(int curr, int nxt, int num_moves){
	if(num_moves % 2 == 0){
		if(curr == 1){
			first = 'A';
			second  = 'B';
		} 
		if(curr == 2){
			first = 'A';
			second = 'C';
		} 
		if(curr == 3){
			first = 'B';
			second = 'C';
		} 
		return;
	}
	
	if(curr == 1 && nxt == 2){
		first = 'A';
		second = 'B';
	}
	if(curr == 2 && nxt == 1){
		first = 'A';
		second = 'C';
	}
	if(curr == 1 && nxt == 3){
		first  = 'B';
		second = 'A';
	}
	if(curr == 3 && nxt == 1){
		first = 'B';
		second = 'C';
	}
	if(curr == 2 && nxt == 3){
		first = 'C';
		second = 'A';
	}
	if(curr == 3 && nxt == 2){
		first = 'C';
		second = 'B';
	}
}

void manipulate(char to_add, char to_sub){
	if(to_add == 'A') a++;
	if(to_add == 'B') b++;
	if(to_add == 'C') c++;
	if(to_sub == 'A') a--;
	if(to_sub == 'B') b--;
	if(to_sub == 'C') c--;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin >> n >> a >> b >> c;

	vector<int> arr;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		if(s == "AB") arr.pb(1);
		if(s == "AC") arr.pb(2);
		if(s == "BC") arr.pb(3);
	}

	if(a == 0 && b == 0 && c == 0){
		cout << "No" << endl;
		return 0;
	}

	if(a >= 1 && b >= 1 && c >= 1){
		for(int i = 0; i < n; i++){
			doMove(arr[i]);
		}
		assert(ans.size() == n);
		cout << "Yes" << endl;
		for(auto i : ans) cout << i << endl;
		return 0;
	}

	int zc = 0;
	if(!a) zc++;
	if(!b) zc++;
	if(!c) zc++;

	if(zc == 1){
		for(int i = 0; i < n; i++){
			int j = i + 1;
			int tot = 1;
			while(j < n && arr[j] == arr[i]){
				tot++;
				j++;
			} 
			if(j != n){
				setFirst(arr[i], arr[j], tot);
			}
			else{
				if(arr[i] == 1){
					first = 'A';
					second = 'B';
				}
				else if(arr[i] == 2){
					first = 'A';
					second  = 'C';
				}
				else if(arr[i] == 3){
					first = 'B';
					second = 'C';
				}
			}

			tot = 0;
			for(int it = i; it < j; it++){
				if(!(tot % 2)){
					ans.pb(first);
					manipulate(first,second);
				} 
				else{
					ans.pb(second);
					manipulate(second, first);
				}
				tot++; 
			}
			i = j - 1;
		}
		}
		assert(ans.size() == n);
		cout << "Yes" << endl;
		for(auto i : ans) cout << i << endl;
	}
	else if(zc == 2){
		for(int i = 0; i < n; i++){
			doMove(arr[i]);
			if(!(a >= 0 && b >= 0 && c >= 0)){
				cout << "No" << endl;
				return 0;
			}
		}
		assert(ans.size() == n);
		cout << "Yes" << endl;
		for(auto i : ans) cout << i << endl;
	}
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Compiler output:
a.cc:263:9: error: expected unqualified-id before 'else'
  263 |         else if(zc == 2){
      |         ^~~~
a.cc:277:9: error: 't2' does not name a type; did you mean 'tm'?
  277 |         t2 = clock();
      |         ^~
      |         tm
a.cc:278:9: error: 'cerr' does not name a type
  278 |         cerr << endl << t2-t1 << endl;
      |         ^~~~
a.cc:280:9: error: expected unqualified-id before 'return'
  280 |         return 0;
      |         ^~~~~~
a.cc:281:1: error: expected declaration before '}' token
  281 | }
      | ^