#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s0;
    cin >> s0;
    string s;
    s += s0[0];
    for (char c : s0)
        if (c != s.back())
            s += c;
    int cnt[3] {};
    for (char c : s)
        ++cnt[c - 'A'];
    char a = min_element(cnt, cnt + 3) - cnt + 'A';
    vector<string> t;
    int lst = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == a) {
            t.push_back(s.substr(lst, i - lst));
            lst = i + 1;
        }
    }
    t.push_back(s.substr(lst));
    char b = (a - 'A' + 1) % 3 + 'A';
    char c = 'A' ^ 'B' ^ 'C' ^ a ^ b;
    string unitb(1, b), unitc(1, c);
    int b1 = 0, b2 = 0, c1 = 0, c2 = 0;
    for (int i = 0; i < t.size(); ++i) {
        if (i != 0 && i != t.size() - 1 && t[i] == unitb) {
            ++b1;
            ++b2;
        } else if (i != 0 && i != t.size() - 1 && t[i] == unitc) {
            ++c1;
            ++c2;
        } else {
            if (t[i].find(b) != -1)
                ++b1;
            if (t[i].find(c) != -1)
                ++c1;
        }
    }
    if (b2 > c1) {
        int k = b2 - c1;
        b2 -= k;
        b1 -= k;
        cnt[a - 'A'] -= k;
        cnt[b - 'A'] -= k;
        vector<string> f;
        for (int i = 0; i < t.size(); ++i) {
            if (i != 0 && i != t.size() - 1 && k > 0 && t[i] == unitb) {
                --k;
                continue;
            }
            f.push_back(move(t[i]));
        }
        t = move(f);
    }
    if (c2 > b1) {
        int k = c2 - b1;
        c2 -= k;
        c1 -= k;
        cnt[a - 'A'] -= k;
        cnt[c - 'A'] -= k;
        vector<string> f;
        for (int i = 0; i < t.size(); ++i) {
            if (i != 0 && i != t.size() - 1 && k > 0 && t[i] == unitc) {
                --k;
                continue;
            }
            f.push_back(move(t[i]));
        }
        t = move(f);
    }
    if (cnt[b - 'A'] > cnt[c - 'A']) {
        int k = cnt[b - 'A'] - cnt[c - 'A'];
        cnt[b - 'A'] -= k;
        for (int i = 0; i < t.size(); ++i) {
            if (k > 0 && !t[i].empty() && (i == 0 || i == t.size() - 1 || t[i].length() > 1) && t[i].back() == b) {
                --k;
                t[i].pop_back();
            }
            if (k > 0 && !t[i].empty() && (i == 0 || i == t.size() - 1 || t[i].length() > 1) && t[i][0] == b) {
                --k;
                t[i] = t[i].substr(1);
            }
        }
    }
    if (cnt[c - 'A'] > cnt[b - 'A']) {
        int k = cnt[c - 'A'] - cnt[b - 'A'];
        cnt[c - 'A'] -= k;
        for (int i = 0; i < t.size(); ++i) {
            if (k > 0 && !t[i].empty() && (i == 0 || i == t.size() - 1 || t[i].length() > 1) && t[i].back() == c) {
                --k;
                t[i].pop_back();
            }
            if (k > 0 && !t[i].empty() && (i == 0 || i == t.size() - 1 || t[i].length() > 1) && t[i][0] == c) {
                --k;
                t[i] = t[i].substr(1);
            }
        }
    }
    int k = cnt[b - 'A'] - cnt[a - 'A'];
    for (int i = 0; i < t.size(); ++i) {
        while (k > 0 && t[i].length() > 2 - (i == 0 || i == t.size() - 1)) {
            --k;
            t[i].pop_back();
            t[i].pop_back();
        }
    }
    for (int i = 0; i < t.size(); ++i) {
        if (i != 0)
            cout << a;
        cout << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 22292