Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<char> ans;
  int n,a,b,c;
  cin >> n >>a >>b >>c;
  vector<string> d(n);
  
  bool out=false;
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  for(int i=0;i<n;i++){
   if(d[i]=="AB"){
     if(i!=n-1 && a==1 && b==1 && c==0){
       if (d[i+1]=="BC"){
         ans.push_back('B');
        a--;
        b++;
       }
       else (d[i+1]=="AC"){
         ans.push_back('A');
        a++;
        b--;
       }
     }
     else if(a==0&&b==0)out=true;
      else if(a >= b){
        ans.push_back('B');
        a--;
        b++;
      }
      else{
        ans.push_back('A');
        a++;
        b--;
      }
    }
    else if(d[i]=="BC"){
      if(i!=n-1 && a==0 && b==1 && c==1){
       if (d[i+1]=="AB"){
         ans.push_back('B');
        c--;
        b++;
       }
       else (d[i+1]=="AC"){
         ans.push_back('C');
        c++;
        b--;
       }
     }
      else if(b==0&&c==0)out=true;
      else if(b >= c){
        ans.push_back('C');
        b--;
        c++;
      }
      else{
        ans.push_back('B');
        b++;
        c--;
      }
    }
    if(d[i]=="AC"){
      if(i!=n-1 && a==1 && b==0 && c==1){
       if (d[i+1]=="AB"){
         ans.push_back('A');
        c--;
        a++;
       }
       else (d[i+1]=="BC"){
         ans.push_back('C');
        c++;
        a--;
       }
     }
      else if(c==0&&a==0)out=true;
      else if(c >= a){
        ans.push_back('A');
        c--;
        a++;
      }
      else{
        ans.push_back('C');
        c++;
        a--;
      }
    }
    if(out)break;
  }
  if(out)cout << "No" <<endl;
  else{
    cout << "Yes" <<endl;
    for(int i=0;i<n;i++){
      cout << ans[i] <<endl;
    }
  }
}



Compiler output:
a.cc: In function 'int main()':
a.cc:21:27: error: expected ';' before '{' token
   21 |        else (d[i+1]=="AC"){
      |                           ^
      |                           ;
a.cc:21:20: warning: ignoring return value of 'bool std::operator==(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]', declared with attribute 'nodiscard' [-Wunused-result]
   21 |        else (d[i+1]=="AC"){
      |             ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:3772:5: note: declared here
 3772 |     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
a.cc:46:27: error: expected ';' before '{' token
   46 |        else (d[i+1]=="AC"){
      |                           ^
      |                           ;
a.cc:46:20: warning: ignoring return value of 'bool std::operator==(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]', declared with attribute 'nodiscard' [-Wunused-result]
   46 |        else (d[i+1]=="AC"){
      |             ~~~~~~~^~~~~~~
/usr/include/c++/14/bits/basic_string.h:3772:5: note: declared here
 3772 |     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
a.cc:71:27: error: expected ';' before '{' token
   71 |        else (d[i+1]=="BC"){
      |                           ^
      |                           ;
a.cc:71:20: warning: ignoring return value of 'bool std::operator==(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]', declared with attribute 'nodiscard' [-Wunused-result]
   71 |        else (d[i+1]=="BC"){
      |             ~~~~~~~^~~~~~~
/usr/include/c++/14/bits/basic_string.h:3772:5: note: declared here
 3772 |     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~