Problem:
Score : 600 points

Problem Statement

There is a game that involves three variables, denoted A, B, and C.

As the game progresses, there will be N events where you are asked to make a choice.
Each of these choices is represented by a string s_i. If s_i is AB, you must add 1 to A or B then subtract 1 from the other; if s_i is AC, you must add 1 to A or C then subtract 1 from the other; if s_i is BC, you must add 1 to B or C then subtract 1 from the other.

After each choice, none of A, B, and C should be negative.

Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

Constraints

1 \leq N \leq 10^5

0 \leq A,B,C \leq 10^9

N, A, B, C are integers.

s_i is AB, AC, or BC.

Input

Input is given from Standard Input in the following format:

N A B C
s_1
s_2
:
s_N

Output

If it is possible to make N choices under the condition, print Yes; otherwise, print No.

Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (A, B, or C) to which you add 1 in the i-th choice.

Sample Input 1

2 1 3 0
AB
AC

Sample Output 1

Yes
A
C

You can successfully make two choices, as follows:

In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.

In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.

Sample Input 2

3 1 0 0
AB
BC
AB

Sample Output 2

No

Sample Input 3

1 0 9 0
AC

Sample Output 3

No

Sample Input 4

8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB

Sample Output 4

Yes
C
B
B
C
C
B
A
A

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int32 n,a,b,c;
vector<char> ans;
vector<string> s;
bool dfs(int32 a,int32 b,int32 c,int32 i){
  if(a < 0 || b < 0 || c < 0)return false;
  if(i==n)return true;
  if(s[i] == "AB"){
    if(dfs(a+1,b-1,c,i+1)){
      ans.pb('A');
      return true;
    }else if(dfs(a-1,b+1,c,i+1)){
      ans.pb('B');
      return true;
    }else{
      return false;
    }
  }else if(s[i] == "BC"){
    if(dfs(a,b+1,c-1,i+1)){
      ans.pb('B');
      return true;
    }else if(dfs(a,b-1,c+1,i+1)){
      ans.pb('C');
      return true;
    }else{
      return false;
    }
  }else{
    if(dfs(a+1,b,c-1,i+1)){
      ans.pb('A');
      return true;
    }else if(dfs(a-1,b,c+1,i+1)){
      ans.pb('C');
      return true;
    }else{
      return false;
    }
  }
  return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b >> c;
  s.resize(n);
  REP(i,n)cin >> s[i];
  if(a+b+c==0){
    Yes(false);
    return 0;
  }
  // if(a+b+c==1){
  //   // vector<string> s(n);
  //   // REP(i,n)cin >> s[i];
  //   // vector<char> ans;
  //   // vector<vector<int32>> cand = {{1,0,0},{0,1,0},{0,0,1}};
  //   // for(auto [x,y,z] : cand){
  //   //   ans.clear();
  //   //   bool flg = true;
  //   //   FORR(i,n-1,0){
  //   //     if(s[i] == 'AB'){
  //   //       if()
  //   //     }else if(s[i] == "BC"){

  //   //     }
  //   //   }
  //   //   if(flg){
  //   //     Yes(true);
  //   //     reverse(ALL(ans));
  //   //     for(auto t : ans)ANS(t);
  //   //     return 0;
  //   //   }
  //   // }
  //   // Yes(false);
  //   return 0;
  // }
  // if(a+b+c==2){
  //   return 0;
  // }
  if(a+b+c == 1 || a+b+c == 2){
    if(dfs(a,b,c,0)){
      reverse(ALL(ans));
      Yes(true);
      for(auto t : ans)ANS(t);
    }else{
      Yes(false);
    }
    return 0;
  }
  REP(i,n){
    if(s[i] == "AB"){
      if(a+b==0){
        Yes(false);
        return 0;
      }
      if(a > b){
        a--;b++;
        ans.pb('B');
      }else{
        a++;b--;
        ans.pb('A');
      }
    }else if(s[i] == "BC"){
      if(b+c==0){
        Yes(false);
        return 0;
      }
      if(b > c){
        b--;c++;
        ans.pb('C');
      }else{
        b++;c--;
        ans.pb('B');
      }
    }else{
      if(a+c==0){
        Yes(false);
        return 0;
      }
      if(a > c){
        a--;c++;
        ans.pb('C');
      }else{
        a++;c--;
        ans.pb('A');
      }
    }
  }
  Yes(true);
  for(auto x : ans)ANS(x);
  return 0;
}