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: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
int main(){
    ll N,A,B,C;
    cin>>N>>A>>B>>C;
    vl vec(N);
    ll countA=0;
    ll countB=0;
    ll countC=0;
    rep(i,N){
        string a;
    cin>>a;
    if(a=="AB"){
        countA++;
        countB++;
        vec.at(i)=0;
    }else if(a=="AC"){
        countC++;
        countA++;
        vec.at(i)=1;
    }else{
        countB++;
        countC++;
        vec.at(i)=2;
    }
    }
    ll MAX,MID,MIN;
    ll ca,cb,cc;
    char x,y,z;
    if(A>=B>=C){
        MAX=A;
        MID=B;
        MIN=C;
        x='A';
        y='B';
        z='C';
        ca=countA;
        cb=countB;
        cc=countC;
    }else if(B>=A>=C){
        MAX=B;
        MID=A;
        MIN=C;
        x='B';
        y='A';
        z='C';
        ca=countB;
        cb=countA;
        cc=countC;
    }else if(C>=A>=B){
        MAX=C;
        MID=A;
        MIN=B;
        x='C';
        y='A';
        z='B';
        ca=countC;
        cb=countA;
        cc=countB;
    }else if(A>=C>=B){
        MAX=A;
        MID=C;
        MIN=B;
        x='A';
        y='C';
        z='B';
        ca=countA;
        cb=countC;
        cc=countB;
    }else if(B>=C>=A){
        MAX=B;
        MID=C;
        MIN=A;
        x='B';
        y='C';
        z='A';
        ca=countB;
        cb=countC;
        cc=countA;
    }else{
        MAX=C;
        MID=B;
        MIN=A;
        x='C';
        y='B';
        z='A';
        ca=countC;
        cb=countB;
        cc=countA;
    }
    ll i=0;
    vector<char> ans(N);
    while(ca>0&&i<N){
        ca--;
        if(MAX>0&&cc>0){
            MIN++;
            MAX--;
            cc--;
            ans.at(i)=z;
        }else if(MAX>0&&cb>0){
            MID++;
            MAX--;
            cb--;
            ans.at(i)=y;
        }else if(MAX==0&&cc>0&&MIN>0){
            MAX++;
            MIN--;
            cc--;
            ans.at(i)=x;
        }else if(MAX==0&&cb>0&&MID>0){
            MAX++;
            MID--;
            cb--;
            ans.at(i)=x;
        }else{
            cN;
            return 0;
        }
        i++;
    }
    while(cb>0&&i<N){
        cb--;
        if(MIN>0&&cc>0){
            MIN++;
            MID--;
            cc--;
            ans.at(i)=z;
        }else if(MID==0&&cc>0&&MIN>0){
            MID++;
            MIN--;
            cc--;
            ans.at(i)=y;
        }else{
            cN;
            return 0;
        }
        i++;
    }
    cY;
    rep(i,N){
        cout<<ans.at(i)<<endl;
    }
}