Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N; cin >> N;
  ll A, B, C; cin >> A >> B >> C;
  vector<string> S(N+1,"AB");
  for(int i=0;i<N;i++){
    cin >> S[i];
  }
  int count=0;
  if(A==0){
    count++;
  }
  if(B==0){
    count++;
  }
  if(C==0){
    count++;
  }
  if(count==3){
    cout << "No" << endl;
    return 0;
  }
  if(count==1 A+B+C==2){
    vector<string> ANS(N);
    for(int i=0;i<N;i++){
      if(S[i]=="AB" && A==0 && B==0){
        cout << "No" << endl;
        return 0;
      }
      if(S[i]=="BC" && B==0 && C==0){
        cout << "No" << endl;
        return 0;
      }
      if(S[i]=="AC" && A==0 && C==0){
        cout << "No" << endl;
        return 0;
      }
      if(i==N-1){
        if(S[i]=="AB"){
          if(A>=B){
            ANS[i]="B";
          }
          else ANS[i]="A";
          break;
        }
        if(S[i]=="BC"){
          if(C>=B){
            ANS[i]="B";
          }
          else ANS[i]="B";
          break;
        }
        if(S[i]=="AC"){
          if(A>=C){
            ANS[i]="C";
          }
          else ANS[i]="A";
          break;
        }
      }
      if(S[i]=="AB"){
        if(A>B){
          ANS[i]="B";
          A--; B++;
          continue;
        }
        if(A<B){
          ANS[i]="A";
          A++; B--;
          continue;
        }
        if(S[i+1]=="AC"){
          ANS[i]="A";
          A++; B--;
          continue;
        }
        ANS[i]="B";
        A--; B++;
        continue;
      }
      if(S[i]=="BC"){
        if(B>C){
          ANS[i]="C";
          B--; C++;
          continue;
        }
        if(B<C){
          ANS[i]="B";
          B++; C--;
          continue;
        }
        if(S[i+1]=="AC"){
          ANS[i]="C";
          C++; B--;
          continue;
        }
        ANS[i]="B";
        C--; B++;
        continue;
      }
      if(S[i]=="AC"){
        if(A>C){
          ANS[i]="C";
          A--; C++;
          continue;
        }
        if(A<C){
          ANS[i]="A";
          A++; C--;
          continue;
        }
        if(S[i+1]=="AB"){
          ANS[i]="A";
          A++; C-;
          continue;
        }
        ANS[i]="C";
        A--; C++;
        continue;
      }
    }
    cout << "Yes" << endl;
    for(int i=0;i<N;i++){
      cout << ANS[i] << endl;
    }
    return 0;
  }
  if(count==2){
    if(max(A,max(B,C))==1){
      vector<string> ans(N); 
      for(int i=0;i<N;i++){
        if(S[i]=="AB"){
          if(A==0 && B==0){
            cout << "No" << endl;
            return 0;
          }
          if(A==1){
            A=0; B=1;
            ans[i]="B";
            continue;
          }
          if(B==1){
            A=1; B=0;
            ans[i]="A";
            continue;
          }
        }
        if(S[i]=="BC"){
          if(C==0 && B==0){
            cout << "No" << endl;
            return 0;
          }
          if(B==1){
            B=0; C=1;
            ans[i]="C";
            continue;
          }
          if(C==1){
            B=1; C=0;
            ans[i]="B";
            continue;
          }
        }
        if(S[i]=="AC"){
          if(A==0 && C==0){
            cout << "No" << endl;
            return 0;
          }
          if(A==1){
            A=0; C=1;
            ans[i]="C";
            continue;
          }
          if(C==1){
            A=1; C=0;
            ans[i]="A";
            continue;
          }
        }
      }
      cout << "Yes" << endl;
      for(int i=0;i<N;i++){
        cout << ans[i] << endl;
      }
      return 0;
    }
    if(S[0]=="AB" && A==0 && B==0){
      cout << "No" << endl;
      return 0;
    }
    if(S[0]=="BC" && C==0 && B==0){
      cout << "No" << endl;
      return 0;
    }
    if(S[0]=="AC" && A==0 && C==0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for(int i=0;i<N;i++){
    if(S[i]=="AB"){
      if(A>=B){
        cout << "B" << endl;
        A--;
        B++;
        continue;
      }
      if(A<B){
        cout << "A" << endl;
        A++;
        B--;
        continue;
      }
    }
    if(S[i]=="BC"){
      if(B>=C){
        cout << "C" << endl;
        B--;
        C++;
        continue;
      }
      if(B<C){
        cout << "B" << endl;
        B++;
        C--;
        continue;
      }
    }
    if(S[i]=="AC"){
      if(A>=C){
        cout << "C" << endl;
        A--;
        C++;
        continue;
      }
      if(A<C){
        cout << "A" << endl;
        A++;
        C--;
        continue;
      }
    }
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:14: error: expected ')' before 'A'
   25 |   if(count==1 A+B+C==2){
      |     ~        ^~
      |              )
a.cc:116:18: error: expected primary-expression before ';' token
  116 |           A++; C-;
      |                  ^