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 <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#include <iostream> 
#include<bits/stdc++.h>
using namespace __gnu_pbds;  
using namespace std;  
// Declaring ordered_set 
typedef tree<long long int, null_type, less<long long int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  
// https://www.geeksforgeeks.org/order_of_key-in-c/
 
typedef pair<long long int,long long int> pa;
 
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
#define  MAX 200005

#define endl "\n"                   //Take care in case of interactive problems


long long int mod=998244353;
long long int MOD=1e9+7;
long long int INF=4e18;
 
 
 
 
////////////////////////////////////////////// sieve  //////////////////////////////////////////////////////////////////

 /*bool C[MAX];
vector<long long  int>V[MAX];
 void sieve()
 {
    long long int i,j;
    for(i=2;i<MAX;i++)
    {
      if(!C[i])
     { 
         
      // D[i]=i;
        for(j=2*i;j<MAX;j=j+i)
        {
            C[j]=true;
            V[j].pb(i);
        }
      }
        
    }
     
 }
 */
 
 
 
//////////////////////////////////////////////////////////D-S-U/////////////////////////////////////////////////////////
/*long long int parent[MAX];
long long int size[MAX];
void initialise()
{ //cout<<MAX<<" ";
    for(long  long int i=0;i<MAX;i++)
    {
        parent[i]=i;
        //cout<<i<<" ";
        size[i]=1;
    }
}
long long int  root(long long int x)
{
    while(x!=parent[x])
    {
        parent[x]=parent[parent[x]];
        x=parent[x];
    }
    return x;
}
 
    
void union1(long long int x,long long int y)
{
    if(size[x]>=size[y])
    {
        size[x]+=size[y];
        parent[y]=x;
        
    }
    else
    {
        size[y]+=size[x];
        parent[x]=y;
    }
}*/
//////////////////////////////////////////////////////MODPOWER//////////////////////////////////////////////////////////
 
 
/*long long int modulo(long long int a,long long  int b, long long int n){
    long long int  x=1, y=a%n; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n; // multiplying with base
        }
        y = (y*y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}*/
 
 
////////////////////////////////////////////////BIT/////////////////////////////////////////////////////////////////////
 /*long long int bit[MAX+1]={0};
long long int query(long long int in,long long int n)
{
    //in=in+1;
    long long int sum=0;
    if(in==0)
        return 0;
    while(in>0)
    {
      sum=sum+bit[in];
        
        in=in-(in&(-in));
    }
    return sum;
}
void update(long long int in,long long int n,long long int val)
{
    // in=in+1;
    
    while(in<=n)
    {
       // cout<<in<<" ";
        bit[in]+=val;
        in=in+ (in &(-in));
    }
}
 
 
 
*/
 
//////////////////////////////////////////////// DFS //////////////////////////////////////////////////////////////////
/*
  bool visited[MAX];
 long long int parent[MAX];
 long long int dist[MAX];


void dfs(vector<long long int>adj[],long long int i,long long int k)
{
    visited[i]=true;
    for(auto j:adj[i])
    {
        if(!visited[j])
        {
            dist[j]=dist[i]+1;
            parent[j]=i;
            dfs(adj,j,k);
            
        }
        
    }
}
 */
 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 

 
 
//long long int R[4]={1,0,-1,0};
//long long int C[4]={0,1,0,-1};
 
 
//SAME SHIT, DIFFERENT DAY! 

long long int dp[105][105];
long long int A[105][105];
int main()
{
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);
  cout.tie(NULL);
long long int  sum,d,i,w,j,k=0,l=0,r=0,m,n,c,p=0,cnt=0,cnt1=0,x,y=0,z=0,a,b,low,mid,high,ans=0,ans1=0,maxi=0,mini=INF,t1,x1,y1,z1,t,o,i1;
string s1,s2,s3;    long long qt,xxx;        char kk,aa,bb,jj;

   cin>>n>>a>>b>>c;
    vector<long long int>V[3];
    string s[n];
    vector<char>L;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        if(s[i][0]=='A' || s[i][1]=='A')
        {
            V[0].pb(i);
        }
         if(s[i][0]=='B' || s[i][1]=='B')
        {
            V[1].pb(i);
        }
        
         if(s[i][0]=='C' || s[i][1]=='C')
        {
            V[2].pb(i);
        }
        
        
    }
    p=0;
    
    for(i=0;i<n;i++)
    {
        x=0;
        y=0;
        z=0;
        if(s[i][0]=='A' || s[i][1]=='A')
        {
            x=1;
        }
         if(s[i][0]=='B' || s[i][1]=='B')
        {
            y=1;
        }
        
         if(s[i][0]=='C' || s[i][1]=='C')
        {
            z=1;
        }
        
        if(x==1 && y==1)
        {
            if(a==1 && b==1)
            {
                  l=upper_bound(V[0].begin(),V[0].end(),i)-V[0].begin();
                  r=upper_bound(V[1].begin(),V[1].end(),i)-V[1].begin();
                if(l<r)
                {
                    a--;
                    b++;
                    L.pb('B');
                }
                else
                {
                    a++;
                    b--;
                    L.pb('A');
                }
                
                  
            }
           else if(a<b)
            {
                b--;
                a++;
               L.pb('A');
            }
            else
            {
                a--;
                b++;
                 L.pb('B');
                
            }
            
            
        }
        if(x==1 && z==1)
        {
            if(a==1 && c==1)
            {
                  l=upper_bound(V[0].begin(),V[0].end(),i)-V[0].begin();
                  r=upper_bound(V[2].begin(),V[2].end(),i)-V[2].begin();
                if(l<r)
                {
                    a--;
                    c++;
                     L.pb('C');
                }
                else
                {
                    a++;
                    c--;
                     L.pb('A');
                }
                
                  
            }
            if(a<c)
            {
                c--;
                a++;
                 L.pb('A');
            }
            else
            {
                a--;
                c++;
                 L.pb('C');
            }
            
            
        }
        if(y==1 && z==1)
        {
            if(b==1 && c==1)
            {
                  l=upper_bound(V[1].begin(),V[1].end(),i)-V[1].begin();
                  r=upper_bound(V[2].begin(),V[2].end(),i)-V[2].begin();
                if(l<r)
                {
                    b--;
                    c++;
                     L.pb('C');
                }
                else
                {
                    b++;
                    c--;
                     L.pb('B');
                }
                
                  
            }
            if(b<c)
            {
                c--;
                b++;
                 L.pb('B');
            }
            else
            {
                b--;
                c++;
                 L.pb('C');
            }
            
        }
        
        
        if(a<0  || b<0 ||c<0)
               p=1;
    }
    
    if(p==0)
    {
        cout<<"Yes\n";
        for(auto ppp:L)
            cout<<ppp<<endl;
    }
    else
        cout<<"No\n";
    
    
}