Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow_(ll a, ll b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  map<char, int> x;
  int a, b, c;
  cin >> a >> b >> c;
  x['A'] = a;
  x['B'] = b;
  x['C'] = c;

  string ans;
  map<string, pii> mp;

  rep(i, n) {
    string s;
    cin >> s;
    pii p = pii(0, 0);
    if (mp[s]) p = mp[s];
    if (mp.count(s)) {
      pii p = mp[s];
      p.F *= -1; p.S *= -1;
      x[s[0]] += p.F;
      x[s[1]] += p.S;
      if (p.F == 1) ans += s[0];
      else ans += s[1];
      mp[s] = p;
    } else {
      if (x[s[0]] < x[s[1]]) {
        pii p = pii(0, 0);
        p.F = 1; p.S = -1;
        x[s[0]] += p.F;
        x[s[1]] += p.S;
        ans += s[0];
        mp[s] = p;
      } else {
        pii p = pii(0, 0);
        p.F = -1; p.S = 1;
        x[s[0]] += p.F;
        x[s[1]] += p.S;
        ans += s[1];
        mp[s] = p;
      }
    }
    for (auto e : x) {
      if (e.S < 0) {
        cout << "No" << endl;
        return;
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, sz(ans)) cout << ans[i] << endl;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:61:14: error: could not convert 'mp.std::map<std::__cxx11::basic_string<char>, std::pair<int, int> >::operator[](s)' from 'std::map<std::__cxx11::basic_string<char>, std::pair<int, int> >::mapped_type' {aka 'std::pair<int, int>'} to 'bool'
   61 |     if (mp[s]) p = mp[s];
      |              ^
      |              |
      |              std::map<std::__cxx11::basic_string<char>, std::pair<int, int> >::mapped_type {aka std::pair<int, int>}