Language: C++

#include<iostream>
#include<string>
#include<vector>

using namespace std;
bool isOK(string, char);
bool isOK(string);

int main() {
    string str;
    bool ans;
    cin >> str;

    ans = isOK(str,'A') || isOK(str,'B') || isOK(str,'C');
    if( ans ) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

bool isOK(string str){
    bool a=true,b=true,c=true;
    if (str == "ABC") return true;
    if(str.size() < 3) return false;
    for(int i=0; i< str.size() ;){
        if( str[i] == 'A'){
            i++;
            //a++;
            if(!(i<str.size())) break;
            if(str[i] == 'B') {
                i++;
                //b++;
                if(!(i<str.size())) break;
                if(str[i] == 'C'){
                    count++;
                    //c++;
                    check.push_back(i-2);
                    //i = i-2;
                    //str.erase(str.begin() + i, str.begin() + i +3);
                    //str.insert(str.begin() + i, mo);
                    i++;
                }else{
                    a=false; b=false;//b++;
                }
            }else{
                if(str[i]=='A')a=false;//b++;
                if(str[i]=='C'){a=false;c=false;}//b++;
            }
        }else{
            if(str[i]=='B')b=false;//b++;
            if(str[i]=='C')c=false;//c++;
            i++;
        }
    }
    if(a)return isOK(isOK(str,'A'));
    if(b)return isOK(isOK(str,'B'));
    if(c)return isOK(isOK(str,'C'));
    return false;
}

string isOK(string str, char mo){
    //int count=0;
    //if (str == "ABC") return true;
    //if(str.size() < 3) return false;
    for(int i=0; i< str.size() ;){
        if( str[i] == 'A'){
            i++;
            //a++;
            if(!(i<str.size())) break;
            if(str[i] == 'B') {
                i++;
                //b++;
                if(!(i<str.size())) break;
                if(str[i] == 'C'){
                    count++;
                    //c++;
                    i = i-2;
                    str.erase(str.begin() + i, str.begin() + i +3);
                    str.insert(str.begin() + i, mo);
                    i++;
                }else{
                   // a=false; b=false;//b++;
                }
            }else{
               // if(str[i]=='A')a=false;//b++;
               // if(str[i]=='C'){a=false;c=false;}//b++;
            }
        }else{
            //if(str[i]=='B')b=false;//b++;
            //if(str[i]=='C')c=false;//c++;
            i++;
        }
    }
    return str;
    /*if(count ==0) {return false;}
    else{ 
        if(a) return isOK(str,'A');
        else if(b) return isOK(str,'B');
        else if(c) return isOK(str,'C');
        else return false;
    }*/
}



Compiler output:
a.cc: In function 'bool isOK(std::string)':
a.cc:34:21: error: 'count' was not declared in this scope
   34 |                     count++;
      |                     ^~~~~
a.cc:36:21: error: 'check' was not declared in this scope
   36 |                     check.push_back(i-2);
      |                     ^~~~~
a.cc:54:21: error: no matching function for call to 'isOK(bool)'
   54 |     if(a)return isOK(isOK(str,'A'));
      |                 ~~~~^~~~~~~~~~~~~~~
a.cc:6:6: note: candidate: 'bool isOK(std::string, char)'
    6 | bool isOK(string, char);
      |      ^~~~
a.cc:6:6: note:   candidate expects 2 arguments, 1 provided
a.cc:20:6: note: candidate: 'bool isOK(std::string)'
   20 | bool isOK(string str){
      |      ^~~~
a.cc:20:18: note:   no known conversion for argument 1 from 'bool' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   20 | bool isOK(string str){
      |           ~~~~~~~^~~
a.cc:55:21: error: no matching function for call to 'isOK(bool)'
   55 |     if(b)return isOK(isOK(str,'B'));
      |                 ~~~~^~~~~~~~~~~~~~~
a.cc:6:6: note: candidate: 'bool isOK(std::string, char)'
    6 | bool isOK(string, char);
      |      ^~~~
a.cc:6:6: note:   candidate expects 2 arguments, 1 provided
a.cc:20:6: note: candidate: 'bool isOK(std::string)'
   20 | bool isOK(string str){
      |      ^~~~
a.cc:20:18: note:   no known conversion for argument 1 from 'bool' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   20 | bool isOK(string str){
      |           ~~~~~~~^~~
a.cc:56:21: error: no matching function for call to 'isOK(bool)'
   56 |     if(c)return isOK(isOK(str,'C'));
      |                 ~~~~^~~~~~~~~~~~~~~
a.cc:6:6: note: candidate: 'bool isOK(std::string, char)'
    6 | bool isOK(string, char);
      |      ^~~~
a.cc:6:6: note:   candidate expects 2 arguments, 1 provided
a.cc:20:6: note: candidate: 'bool isOK(std::string)'
   20 | bool isOK(string str){
      |      ^~~~
a.cc:20:18: note:   no known conversion for argument 1 from 'bool' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   20 | bool isOK(string str){
      |           ~~~~~~~^~~
a.cc: At global scope:
a.cc:60:8: error: ambiguating new declaration of 'std::string isOK(std::string, char)'
   60 | string isOK(string str, char mo){
      |        ^~~~
a.cc:6:6: note: old declaration 'bool isOK(std::string, char)'
    6 | bool isOK(string, char);
      |      ^~~~
a.cc: In function 'std::string isOK(std::string, char)':
a.cc:74:21: error: 'count' was not declared in this scope
   74 |                     count++;
      |                     ^~~~~