Language: C++

#include <bits/stdc++.h>
std::vector<std::string>s(1e5 + 1);
std::string ans;
int N;
bool dfs(int n,int a,int b,int c,std::string &tmp){
  if(!ans.empty())return true;
  if(a < 0 || b < 0 || c < 0)return false;
  if(n == N){
    for(int i = 0; i < n; i++)ans.push_back(tmp[i]);
    return true;
  }
  if(s[n] == "AB"){
    return dfs(n + 1,a + 1,b - 1,c,tmp + "A") || dfs(n + 1,a - 1,b + 1,c,tmp + "B");
  }
  if(s[n] == "AC"){
    return dfs(n + 1,a + 1,b,c - 1,tmp + "A") || dfs(n + 1,a - 1,b,c + 1,tmp + "C");
  }
  if(s[n] == "BC"){
    return dfs(n + 1,a,b + 1,c - 1,tmp + "B") || dfs(n + 1,a,b - 1,c + 1,tmp + "C");
  }
  return false;
}
int main(){
  int a,b,c;
  std::cin >> N >> a >> b >> c;
  for(int i = 0; i < N; i++)std::cin >> s[i];
  std::string tmp;
  if(dfs(0,a,b,c,tmp)){
    std::cout << "Yes" << std::endl;
    for(int i = 0; i < N; i++)std::cout << ans[i] << std::endl;
  }
  else{
    std::cout << "No" << std::endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'bool dfs(int, int, int, int, std::string&)':
a.cc:13:40: error: cannot bind non-const lvalue reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to an rvalue of type 'std::__cxx11::basic_string<char>'
   13 |     return dfs(n + 1,a + 1,b - 1,c,tmp + "A") || dfs(n + 1,a - 1,b + 1,c,tmp + "B");
      |                                    ~~~~^~~~~
a.cc:5:47: note:   initializing argument 5 of 'bool dfs(int, int, int, int, std::string&)'
    5 | bool dfs(int n,int a,int b,int c,std::string &tmp){
      |                                  ~~~~~~~~~~~~~^~~
a.cc:13:78: error: cannot bind non-const lvalue reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to an rvalue of type 'std::__cxx11::basic_string<char>'
   13 |     return dfs(n + 1,a + 1,b - 1,c,tmp + "A") || dfs(n + 1,a - 1,b + 1,c,tmp + "B");
      |                                                                          ~~~~^~~~~
a.cc:5:47: note:   initializing argument 5 of 'bool dfs(int, int, int, int, std::string&)'
    5 | bool dfs(int n,int a,int b,int c,std::string &tmp){
      |                                  ~~~~~~~~~~~~~^~~
a.cc:16:40: error: cannot bind non-const lvalue reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to an rvalue of type 'std::__cxx11::basic_string<char>'
   16 |     return dfs(n + 1,a + 1,b,c - 1,tmp + "A") || dfs(n + 1,a - 1,b,c + 1,tmp + "C");
      |                                    ~~~~^~~~~
a.cc:5:47: note:   initializing argument 5 of 'bool dfs(int, int, int, int, std::string&)'
    5 | bool dfs(int n,int a,int b,int c,std::string &tmp){
      |                                  ~~~~~~~~~~~~~^~~
a.cc:16:78: error: cannot bind non-const lvalue reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to an rvalue of type 'std::__cxx11::basic_string<char>'
   16 |     return dfs(n + 1,a + 1,b,c - 1,tmp + "A") || dfs(n + 1,a - 1,b,c + 1,tmp + "C");
      |                                                                          ~~~~^~~~~
a.cc:5:47: note:   initializing argument 5 of 'bool dfs(int, int, int, int, std::string&)'
    5 | bool dfs(int n,int a,int b,int c,std::string &tmp){
      |                                  ~~~~~~~~~~~~~^~~
a.cc:19:40: error: cannot bind non-const lvalue reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to an rvalue of type 'std::__cxx11::basic_string<char>'
   19 |     return dfs(n + 1,a,b + 1,c - 1,tmp + "B") || dfs(n + 1,a,b - 1,c + 1,tmp + "C");
      |                                    ~~~~^~~~~
a.cc:5:47: note:   initializing argument 5 of 'bool dfs(int, int, int, int, std::string&)'
    5 | bool dfs(int n,int a,int b,int c,std::string &tmp){
      |                                  ~~~~~~~~~~~~~^~~
a.cc:19:78: error: cannot bind non-const lvalue reference of type 'std::string&' {aka 'std::__cxx11::basic_string<char>&'} to an rvalue of type 'std::__cxx11::basic_string<char>'
   19 |     return dfs(n + 1,a,b + 1,c - 1,tmp + "B") || dfs(n + 1,a,b - 1,c + 1,tmp + "C");
      |                                                                          ~~~~^~~~~
a.cc:5:47: note:   initializing argument 5 of 'bool dfs(int, int, int, int, std::string&)'
    5 | bool dfs(int n,int a,int b,int c,std::string &tmp){
      |                                  ~~~~~~~~~~~~~^~~