Problem:
ABC Gene
文字列
ABC
で表される遺伝子配列がある。あなたは次の操作を何回か行い、この遺伝子配列を書き換えていくことができる。
文字
A
，
B
，
C
のうち
1
つを選ぶ。これを
x
とおく。遺伝子配列に含まれるすべての
x
をそれぞれ
ABC
へ同時に置き換える。
A
，
B
，
C
だけからなる文字列
S
が与えられる。遺伝子配列を
S
に一致させられるか判定せよ。
Constraints
1
≤
|S|
≤
5,000
S
は
A
，
B
，
C
だけからなる。
Input Format
入力は以下の形式で標準入力から与えられる。
S
Output Format
遺伝子配列を
S
に一致させられるならば
Yes
を、一致させられないならば
No
を一行に出力せよ。
Sample Input 1
ABC
Sample Output 1
Yes
遺伝子配列ははじめから
ABC
である。
Sample Input 2
AABCC
Sample Output 2
Yes
B
を選んで操作を行うと
ABC
→
AABCC
となる。
Sample Input 3
AABCABC
Sample Output 3
No
例えば、
C
を選んで操作を行っても
AABCC
→
AABCABC
とはならない。すべての
C
をそれぞれ
ABC
へ同時に置き換えるので、実際は
AABCC
→
AABABCABC
となる。

Submitted solutions:

code_snippet: //#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void) {
	string s;
	cin >> s;
	while (true) {
		if(s.size() <= 3) break;
		//cout << s << endl;
		int f = 1;
		if(s.substr(0, 3) == "ABC") f = 0;
		else if(s.substr(s.size()-3, 3) == "ABC") f = 2;
		int sz = s.size();
		bool up = false;
		REP(i, sz-2) {
			//cout << i << " " << s << " " << s.substr(i, 3) << endl;
			if(i >= s.size()) break;
			if(f == 0 && s[i] == 'A' && s.substr(i, 3) != "ABC") {cout << "No" << endl; return 0;} 
			if(f == 1 && s[i] == 'B' && i > 0 && s.substr(i-1, 3) != "ABC") {cout << "No" << endl; return 0;} 
			if(f == 2 && s[i] == 'C' && i > 1 && s.substr(i-2, 3) != "ABC") {cout << "No" << endl; return 0;} 
			if(s.substr(i, 3) == "ABC") {
				if(f == 0) s = s.substr(0, i) + "A" + s.substr(i+3);
				else if(f == 1) s = s.substr(0, i) + "B" + s.substr(i+3);
				else if(f == 2) s = s.substr(0, i) + "C" + s.substr(i+3);
				up = true;
			}
		}
		if(!up) break;
	}
	//cout << s << endl;
	if(s == "ABC") cout << "Yes" << endl;
	else cout << "No" << endl;

  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3552
final_rank: 7

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// #ifndef ONLINE_JUDGE
// #define _GLIBCXX_DEBUG // 配列外参照のエラー
// #endif

// スタンダードライブラリ
#include <bits/stdc++.h>
using namespace std;

// 型関連
using ll = long long;
using lint = long long;
using pll = pair<ll, ll>;
using plll = tuple<ll, ll, ll>;
using pii = pair<int, int>;
using piii = tuple<ll, ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vvvvl = vector<vector<vector<vector<ll>>>>;

template <class T> using prique = priority_queue<T>;
template<class T> void chmin(T& a, T b){ if(a > b) a = b; }
template<class T> void chmax(T& a, T b){ if(a < b) a = b; }


#define all(v) v.begin(), v.end()

// 型定数
constexpr ll mod = 998244353;
constexpr ll MOD = 1000000007;
int INF32 = 2e9;
ll INF64 = 9e18;
#define endl '\n';

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

/////////////////////////// print関連
template <typename T> void print(vector<T> A);
void print();
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail);
void print(string S);
template <typename T> void print(vector<vector<T>> &F);

inline void Yes(bool f);


///////////////////ここから//////////////////////
bool solve(string S) {
    if (S == "ABC")
        return true;
    bool exist = false;
    set<char> se;
    for (int i = 0; i < S.size(); i++) {
        if (i + 2 < S.size() && S.substr(i, 3) == "ABC") {
            i += 2;
            exist = true;
            continue;
        }
        se.insert(S[i]);
    }
    if (se.size() != 2)
        return false;
    if (!exist)
        return false;
    char c = 'A';
    while (se.count(c))
        c++;
    string nS="";
    for (int i = 0; i < S.size(); i++) {
        if (i + 2 < S.size() && S.substr(i, 3) == "ABC") {
            i += 2;
            nS += c;
            continue;
        }
        nS+=S[i];
    }
    return solve(nS);
}


int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string S;
    cin >> S;
    Yes(solve(S));
    
}

////////////////////print/////////////////////////
// 1次元ベクトルを出力する
template <typename T> void print(vector<T> A) {
    if (A.size() == 0) {
        return;
    }
    for (size_t i = 0; i < A.size() - 1; i++) {
        cout << A[i] << ' ';
    }
    cout << A[A.size() - 1] << endl;
    return;
}

// 2次元ベクトルを出力する
template <typename T> void print(vector<vector<T>> &F) {
    for (size_t i = 0; i < F.size(); i++) {
        for (size_t j = 0; j < F[i].size(); j++) {
            cout << F[i][j];
            if (j < F[i].size() - 1) {
                cout << ' ';
            }
        }
        cout << endl;
    }
}

// 空白行を出力するprint
void print() { cout << endl; }

// 数値・文字列を空白区切りで出力する. print(a,b)など
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

void print(string S) { cout << S << endl; }

//////////////出力関連

inline void Yes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
accuracy: 1
time_ms: 130
memory_kb: 19584
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    string s;
    cin >> s;

    vector<ll> a(s.size());
    for (ll i = 0; i < s.size(); i++) {
        a[i] = s[i] - 'A';
    }
    while (a.size() > 3) {
        vector<ll> b;
        vector<bool> used(3);
        bool q = false;
        for (ll i = 0; i < a.size();) {
            if (i + 2 < a.size() && a[i] == 0 && a[i + 1] == 1 && a[i + 2] == 2) {
                b.push_back(-1);
                q = true;
                i += 3;
            } else {
                b.push_back(a[i]);
                used[a[i]] = true;
                i++;
            }
        }
        ll cnt = used[0] + used[1] + used[2];
        if (!q || cnt != 2) {
            break;
        }
        ll x;
        for (ll i = 0; i < 3; i++) {
            if (!used[i]) {
                x = i;
            }
        }
        for (ll i = 0; i < b.size(); i++) {
            if (b[i] == -1) {
                b[i] = x;
            }
        }
        a = b;
    }
    if (a == vector<ll>{0, 1, 2}) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3556
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
#ifdef DEBUG_Q
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s;
    cin >> s;

    vector<ll> a(s.size());
    for (ll i = 0; i < s.size(); i++) {
        a[i] = s[i] - 'A';
    }
    while (a.size() > 3) {
        vector<ll> b;
        vector<bool> used(3);
        bool q = false;
        for (ll i = 0; i < a.size();) {
            if (i + 2 < a.size() && a[i] == 0 && a[i + 1] == 1 && a[i + 2] == 2) {
                b.push_back(-1);
                q = true;
                i += 3;
            } else {
                b.push_back(a[i]);
                used[a[i]] = true;
                i++;
            }
        }
        ll cnt = used[0] + used[1] + used[2];
        if (!q || cnt != 2) {
            break;
        }
        ll x;
        for (ll i = 0; i < 3; i++) {
            if (!used[i]) {
                x = i;
            }
        }
        for (ll i = 0; i < b.size(); i++) {
            if (b[i] == -1) {
                b[i] = x;
            }
        }
        a = b;
    }
    if (a == vector<ll>{0, 1, 2}) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3592
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

bool Solve(string S) {
    if (S == "ABC") return true;
    if (S.size() <= 3) return false;
    string T = "";
    int ID = 0;
    int B[3] = {};
    while(ID < S.size()) {
        if (ID + 3 <= S.size() && S.substr(ID,3) == "ABC") {
            T += 'D';
            ID += 3;
        }
        else {
            T += S[ID];
            B[S[ID] - 'A'] = 1;
            ID++;
        }
    }
    if (B[0] + B[1] + B[2] != 2) return false;
    int C = 3;
    if (B[1] == 1) C--;
    if (B[2] == 1) C-=2;
    rep(i,0,T.size()) {
        if (T[i] == 'D') T[i] = 'A' + C;
    }
    return Solve(T);
}

int main() {
    string S;
    cin >> S;
    cout << (Solve(S) ? "Yes" : "No") << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 19136
final_rank: 9

code_snippet: // competitive-verifier: PROBLEM
#ifdef ATCODER
#pragma GCC target("sse4.2,avx512f,avx512dq,avx512ifma,avx512cd,avx512bw,avx512vl,bmi2")
#endif
#pragma GCC optimize("Ofast,fast-math,unroll-all-loops")
#include <bits/stdc++.h>
#ifndef ATCODER
#pragma GCC target("sse4.2,avx2,bmi2")
#endif
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = 3.14159265358979323846;
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(20);
    }
    constexpr void operator()() const {}
} sonic;
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) os << (it == v.begin() ? "" : " ") << *it;
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
void Yes(bool is_correct = true) { std::cout << (is_correct ? "Yes\n" : "No\n"); }
void No(bool is_not_correct = true) { Yes(!is_not_correct); }
void YES(bool is_correct = true) { std::cout << (is_correct ? "YES\n" : "NO\n"); }
void NO(bool is_not_correct = true) { YES(!is_not_correct); }
void Takahashi(bool is_correct = true) { std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n'; }
void Aoki(bool is_not_correct = true) { Takahashi(!is_not_correct); }
int main(void)
{
    string s;
    cin >> s;
    while (s != "ABC")
    {
        if (s.size() <= 3)
        {
            No();
            return 0;
        }
        string t;
        int p = 0;
        if (s.substr(0, 3) == "ABC")
        {
            while (p < s.size())
            {
                if (s.substr(p, 3) == "ABC")
                {
                    t += 'A';
                    p += 3;
                }
                else
                {
                    if (s[p] == 'A')
                    {
                        No();
                        return 0;
                    }
                    t += s[p];
                    ++p;
                }
            }
        }
        else if (s.substr(s.size() - 3) == "ABC")
        {
            while (p < s.size())
            {
                if (s.substr(p, 3) == "ABC")
                {
                    t += 'C';
                    p += 3;
                }
                else
                {
                    if (s[p] == 'C')
                    {
                        No();
                        return 0;
                    }
                    t += s[p];
                    ++p;
                }
            }
        }
        else
        {
            while (p < s.size())
            {
                if (s.substr(p, 3) == "ABC")
                {
                    t += 'B';
                    p += 3;
                }
                else
                {
                    if (s[p] == 'B')
                    {
                        No();
                        return 0;
                    }
                    t += s[p];
                    ++p;
                }
            }
            if (s.size() == t.size())
            {
                No();
                return 0;
            }
        }
        s = t;
    }
    Yes();
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3524
final_rank: 5

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

int main(){
    string S;cin >> S;
    while (true){
        string nw = "", X = "";
        for (int i = 0; i < len(S); i++){
            if (len(S) - i >= 3){
                if (len(X) && S.substr(i, 3) == X){
                    nw += 'x';
                    i += 2;
                    continue;
                }
                if (!len(X)){
                    string A = "ABC";
                    int cnt = 0, cntx = 0;
                    rep(j, 3){
                        if (A[j] != S[i + j]) cnt++;
                        if (S[i + j] == 'x') cntx++;
                    }
                    if (cnt == cntx && cnt <= 1){
                        X = S.substr(i, 3);
                        nw += 'x';
                        i += 2;
                        continue;
                    }
                }
            }
            nw += S[i];
        }
        if (nw == S) break;
        swap(nw, S);
    }
    if (S != "x") cout << "No" << endl;
    else cout << "Yes" << endl;
}
accuracy: 0.3103448275862069
time_ms: 50
memory_kb: 3448
final_rank: 16

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

int main(){
    string S;cin >> S;
    while (true){
        string nw = "", X = "";
        for (int i = 0; i < len(S); i++){
            if (len(S) - i >= 3){
                if (len(X) && S.substr(i, 3) == X){
                    nw += 'x';
                    i += 2;
                    continue;
                }
                if (!len(X)){
                    string A = "ABC";
                    int cnt = 0;
                    rep(j, 3) if (A[j] != S[i + j]) cnt++;
                    if (cnt <= 1){
                        X = S.substr(i, 3);
                        nw += 'x';
                        i += 2;
                        continue;
                    }
                }
            }
            nw += S[i];
        }
        if (nw == S) break;
        swap(nw, S);
    }
    if (S != "x") cout << "No" << endl;
    else cout << "Yes" << endl;
}
accuracy: 0.29310344827586204
time_ms: 50
memory_kb: 3432
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    string s;
    cin >> s;
    if((int)s.size() < 3) {
        cout << "No" << '\n';
        return 0;
    }
    while((int)s.size() >= 3) {
        int n = s.size();
        string nex = "";
        if(s.substr(0, 3) == "ABC") {
            rep(i, 0, n) {
                if(i <= n - 3 and s.substr(i, 3) == "ABC") {
                    nex += "A";
                    i += 2;
                } else {
                    if(s[i] == 'A') {
                        cout << "No" << '\n';
                        return 0;
                    }
                    nex += s[i];
                }
            }
        } else if(s.substr(n - 3) == "ABC") {
            rep(i, 0, n) {
                if(i <= n - 3 and s.substr(i, 3) == "ABC") {
                    nex += "C";
                    i += 2;
                } else {
                    if(s[i] == 'C') {
                        cout << "No" << '\n';
                        return 0;
                    }
                    nex += s[i];
                }
            }
        } else {
            rep(i, 0, n) {
                if(i <= n - 3 and s.substr(i, 3) == "ABC") {
                    nex += "B";
                    i += 2;
                } else {
                    if(s[i] == 'B') {
                        cout << "No" << '\n';
                        return 0;
                    }
                    nex += s[i];
                }
            }
        }
        if(s == nex) break;
        s = nex;
    }
    if(s == "A") {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}
accuracy: 1
time_ms: 60
memory_kb: 3496
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
int main(void) {
    string s;
    cin >> s;
    if((int)s.size() < 3) {
        cout << "No" << '\n';
        return 0;
    }
    while((int)s.size() >= 3) {
        int n = s.size();
        string nex = "";
        if(s.substr(0, 3) == "ABC") {
            rep(i, 0, n) {
                if(i <= n - 3 and s.substr(i, 3) == "ABC") {
                    nex += "A";
                    i += 2;
                } else {
                    nex += s[i];
                }
            }
        } else if(s.substr(n - 3) == "ABC") {
            rep(i, 0, n) {
                if(i <= n - 3 and s.substr(i, 3) == "ABC") {
                    nex += "C";
                    i += 2;
                } else {
                    nex += s[i];
                }
            }
        } else {
            rep(i, 0, n) {
                if(i <= n - 3 and s.substr(i, 3) == "ABC") {
                    nex += "B";
                    i += 2;
                } else {
                    nex += s[i];
                }
            }
        }
        if(s == nex) break;
        s = nex;
    }
    if(s == "A") {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
}
accuracy: 0.9137931034482759
time_ms: 70
memory_kb: 3456
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

string Simulation(string S) {
    // First
    vector<bool> Digit(S.size(), false);
    vector<bool> Check(3, false);
    int cur = 0;
    while (cur < S.size()) {
        if (cur + 2 < S.size() && S[cur] == 'A' && S[cur + 1] == 'B' && S[cur + 2] == 'C') {
            Digit[cur + 0] = true;
            Digit[cur + 1] = true;
            Digit[cur + 2] = true;
            cur += 3;
        }
        else { Check[S[cur] - 'A'] = true; cur += 1; }
    }

    // Second
    int idx = -1;
    for (int i = 0; i < 3; i++) {
        if (Check[i] == false) { idx = i; break; }
    }
    if (idx == -1) return S;

    // Third
    string str = "";
    int cx = 0;
    while (cx < S.size()) {
        if (Digit[cx] == true) { str += ('A' + idx); cx += 3; }
        else { str += S[cx]; cx += 1; }
    }
    return str;
}

int main() {
    // Step 1. Input
    string S; cin >> S;

    // Step 2. Simulation
    while (S != "ABC") {
        string T = Simulation(S);
        if (T == S) break;
        S = T;
    }

    // Step 3. Output
    if (S == "ABC") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3440
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

bool solve() {
    string s;
    cin >> s;
    while (s.size() > 3) {
        vector<int> cnt(3), id;
        for (int i = 0; i < s.size(); i++) {
            if (i >= 2 && s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C') {
                id.push_back(i - 2);
                cnt[0]--;
                cnt[1]--;
            } else {
                cnt[2 - ('C' - s[i])]++;
            }
        }
        if (*min_element(cnt.begin(), cnt.end()) != 0) break;
        int i = 0;
        char c = 'A' + (min_element(cnt.begin(), cnt.end()) - cnt.begin());
        string t;
        for (int x : id) {
            for (;i < x; i++) {
                t.push_back(s[i]);
            }
            t.push_back(c);
            i = x + 3;
        }
        for (; i < s.size(); i++) {
            t.push_back(s[i]);
        }
        if (s == t) break;
        s = t;
    }
    cout << (s == "ABC" ? "Yes" : "No") << endl;
    return false;
}

int main() {
    while (solve());
}
accuracy: 1
time_ms: 10
memory_kb: 3468
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

bool solve() {
    string s;
    cin >> s;
    while (s.size() > 3) {
        vector<int> cnt(3), id;
        for (int i = 0; i < s.size(); i++) {
            if (i >= 2 && s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C') {
                id.push_back(i - 2);
                cnt[0]--;
                cnt[1]--;
            } else {
                cnt[2 - ('C' - s[i])]++;
            }
        }
        int i = 0;
        char c = 'A' + (min_element(cnt.begin(), cnt.end()) - cnt.begin());
        string t;
        for (int x : id) {
            for (;i < x; i++) {
                t.push_back(s[i]);
            }
            t.push_back(c);
            i = x + 3;
        }
        for (; i < s.size(); i++) {
            t.push_back(s[i]);
        }
        if (s == t) break;
        s = t;
    }
    cout << (s == "ABC" ? "Yes" : "No") << endl;
    return false;
}

int main() {
    while (solve());
}
accuracy: 0.9310344827586207
time_ms: 10
memory_kb: 3464
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin>>S;
  while(S.size()>3){
    int N=S.size();
    set<char>s;
    for(int i=0;i<N;i++){
      if(S.substr(i,3)=="ABC"){
        i+=2;
      }else{
        s.insert(S[i]);
      }
    }
    if(s.size()!=2){
      cout<<"No\n";
      return 0;
    }
    char c='/';
    if(s.find('A')==s.end())c='A';
    if(s.find('B')==s.end())c='B';
    if(s.find('C')==s.end())c='C';
    string T="";
    for(int i=0;i<N;i++){
      if(S.substr(i,3)=="ABC"){
        T+=c;
        i+=2;
      }else{
        T+=S[i];
      }
    }
    S=T;
  }
  cout<<(S=="ABC"?"Yes\n":"No\n");
}
accuracy: 1
time_ms: 140
memory_kb: 3484
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin>>S;
  while(S.size()>3){
    char c1='/',c2='/';
    for(int i=0;i<S.size()-2;i++){
      if(S.substr(i,3)=="ABC"){
        if(i==0){
          c1='A';
          break;
        }
        if(i+3==S.size()){
          c2='C';
          break;
        }
        if(i>0){
          c1=(S[i-1]-'A'+1)%3+'A';
        }
        if(i+3<S.size()){
          c2=(S[i+3]-'A'+2)%3+'A';
        }
        break;
      }
    }
    if(c1=='/'&&c2=='/'){
      cout<<"No\n";
      return 0;
    }
    if(c1!='/'&&c2!='/'&&c1!=c2){
      cout<<"No\n";
      return 0;
    }
    char c='/';
    if(c1!='/')c=c1;
    if(c2!='/')c=c2;
    string T="";
    for(int i=0;i<S.size();i++){
      if(S.substr(i,3)=="ABC"){
        T+=c;
        i+=2;
      }else{
        T+=S[i];
        if(S[i]==c){
          cout<<"No\n";
          return 0;
        }
      }
    }
    S=T;
  }
  cout<<(S=="ABC"?"Yes\n":"No\n");
}
accuracy: 0.3103448275862069
time_ms: 120
memory_kb: 3408
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin>>S;
  while(S.size()>3){
    char c1='/',c2='/';
    for(int i=0;i<S.size()-3;i++){
      if(S.substr(i,3)=="ABC"){
        if(i==0){
          c1='A';
          break;
        }
        if(i+3==S.size()){
          c2='C';
          break;
        }
        if(i>0){
          c1=(S[i-1]-'A'+1)%3+'A';
        }
        if(i+3<S.size()){
          c2=(S[i+3]-'A'+2)%3+'A';
        }
        break;
      }
    }
    if(c1=='/'&&c2=='/'){
      cout<<"No\n";
      return 0;
    }
    if(c1!='/'&&c2!='/'&&c1!=c2){
      cout<<"No\n";
      return 0;
    }
    char c='/';
    if(c1!='/')c=c1;
    if(c2!='/')c=c2;
    string T="";
    for(int i=0;i<S.size();i++){
      if(S.substr(i,3)=="ABC"){
        T+=c;
        i+=2;
      }else{
        T+=S[i];
        if(S[i]==c){
          cout<<"No\n";
          return 0;
        }
      }
    }
    S=T;
  }
  cout<<(S=="ABC"?"Yes\n":"No\n");
}
accuracy: 0.29310344827586204
time_ms: 90
memory_kb: 3508
final_rank: 20

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    string S;
    cin >> S;

    auto dfs = [&](auto &&self, string s, char t) -> void {
        int n = s.size();
        if (s == "ABC") {
            cout << "Yes\n";
            exit(0);
        }
        if (n <= 3) return;

        bool update = false;
        string res = "";
        vector<bool> used(3);
        rep(i, n) {
            if (s.substr(i, 3) == "ABC") {
                res += t;
                i += 2;
                update = true;
            } else {
                res += s[i];
                used[s[i] - 'A'] = true;
            }
        }

        if (used[t - 'A']) return;

        if (update) {
            self(self, res, 'A');
            self(self, res, 'B');
            self(self, res, 'C');
        }
        return;
    };

    dfs(dfs, S, 'A');
    dfs(dfs, S, 'B');
    dfs(dfs, S, 'C');

    cout << "No\n";

    return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 19228
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(0);

    string S;
    cin >> S;

    auto dfs = [&](auto &&self, string s, char t) -> void {
        int n = s.size();
        if (s == "ABC") {
            cout << "Yes\n";
            exit(0);
        }
        if (n <= 3) return;

        bool update = false;
        string res = "";
        vector<bool> used(3);
        rep(i, n) {
            if (s.substr(i, 3) == "ABC") {
                res += t;
                i += 2;
                update = true;
            } else {
                used[s[i] - 'A'] = true;
                res += s[i];
            }
        }

        if (update) {
            rep(i, 3) {
                if (used[i]) continue;
                self(self, res, 'A' + i);
            }
        }
    };

    dfs(dfs, S, 'A');
    dfs(dfs, S, 'B');
    dfs(dfs, S, 'C');

    cout << "No\n";

    return 0;
}
accuracy: 0.3103448275862069
time_ms: 70
memory_kb: 19336
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    string S{}; cin >> S;

    auto sed = [](string S, char c) -> string {
        string res{};
        for (size_t i = 0 ; i < S.size() ; i++) {
            if (i + 2 < S.size() and S[i] == 'A' and S[i + 1] == 'B' and S[i + 2] == 'C') {
                res += c;
                i += 2;
            }
            else {
                res += S[i];
            }
        }
        return res;
    };
   
    while (S.size() > 3) {
        if (S.front() != 'A' or S.back() != 'C') {
            cout << "No" << endl;
            return 0;
        }
        if (S.substr(0, 3) == "ABC" and S.substr(S.size() - 3, 3) == "ABC") {
            cout << "No" << endl;
            return 0;
        }
        string nxt{};
        if (S.substr(0, 3) == "ABC") 
            nxt = sed(S, 'A');
        else if (S.substr(S.size() - 3, 3) == "ABC")
            nxt = sed(S, 'C');
        else 
            nxt = sed(S, 'B');

        if (S == nxt) {
            cout << "No" << endl;
            return 0;
        }

        S = move(nxt);
    }

    if (S == "ABC") {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
accuracy: 0.9137931034482759
time_ms: 10
memory_kb: 3456
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    string S{}; cin >> S;

    auto sed = [](string S, char c) -> string {
        string res{};
        for (size_t i = 0 ; i < S.size() ; i++) {
            if (i + 2 < S.size() and S[i] == 'A' and S[i + 1] == 'B' and S[i + 2] == 'C') {
                res += c;
                i += 2;
            }
            else {
                res += S[i];
            }
        }
        return res;
    };
   
    while (S.size() > 3) {
        string nxt{};
        if (S.substr(0, 3) == "ABC") 
            nxt = sed(S, 'A');
        else if (S.substr(S.size() - 3, 3) == "ABC")
            nxt = sed(S, 'C');
        else 
            nxt = sed(S, 'B');

        if (S == nxt) {
            cout << "No" << endl;
            return 0;
        }

        S = move(nxt);
    }

    if (S == "ABC") {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
accuracy: 0.9137931034482759
time_ms: 10
memory_kb: 3488
final_rank: 14