#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
#include<numeric>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

struct BidirectionalList;

set<BidirectionalList*> pos[4][4][4];
int cnt[3];

struct BidirectionalList{
    BidirectionalList *prev, *next;
    int val;

    BidirectionalList(int v):val(v), prev(nullptr), next(nullptr){}
    BidirectionalList *remove(){
        auto n = this->next, p = this->prev;
        if(n)n->prev = p;
        if(p)p->next = n;
        cnt[this->val]--;
        return n;
    }

    void insert(BidirectionalList &new_next){
        auto n = this->next;
        if(n)n->prev = &new_next;                   
        new_next.next = n;
        this->next = &new_next;
        new_next.prev = this;
    }

    void set_triple(){
        if(val < 3)
            pos[prev->val][val][next->val].insert(this);
    }

    void unset_triple(){
        if(val < 3)
            pos[prev->val][val][next->val].erase(this);
    }
};

BidirectionalList *remove(BidirectionalList *x){
    if(x->prev->val != x->next->val){
        auto n = x->next, p = x->prev;
        x->unset_triple();
        n->unset_triple();
        p->unset_triple();
        x->remove();
        n->set_triple();
        p->set_triple();
        return n;
    }
    else{
        auto n = x->next, p = x->prev, nn = x->next->next;
        x->unset_triple();
        n->unset_triple();
        nn->unset_triple();
        p->unset_triple();

        x->remove();
        n->remove();
        
        nn->set_triple();
        p->set_triple();
        return n;
    }
}


// remove b
bool check(int a, int b, int c){
    if(pos[a][b][c].empty())return false;
    auto tmp = *pos[a][b][c].begin();pos[a][b][c].erase(pos[a][b][c].begin());
    remove(tmp);
    return true;
}

int main(){
    string s;
    cin >> s;
    BidirectionalList start(3), end(3);
    start.insert(end);
    auto last = &start;
    for(char c:s){
        if(c-'A' == last->val)continue;
        BidirectionalList *tmp = new BidirectionalList(c-'A');       
        last->insert(*tmp);
        last = tmp;
    }

    int n = s.size();
    for(auto it = start.next;it != &end;it = it->next){
        cnt[it->val]++;
        it->set_triple();
    }

    if(cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0){
        cout << endl;
        return 0;
    }

    while(cnt[0] != cnt[1] || cnt[1] != cnt[2]){
        int ord[] = {0, 1, 2};
        if(cnt[ord[0]] < cnt[ord[1]])swap(ord[0], ord[1]);
        if(cnt[ord[1]] < cnt[ord[2]])swap(ord[1], ord[2]);
        if(cnt[ord[0]] < cnt[ord[1]])swap(ord[0], ord[1]);

        int min_cnt = cnt[ord[2]];
        int only_0 = pos[ord[2]][ord[0]][ord[2]].size();
        int only_1 = pos[ord[2]][ord[1]][ord[2]].size();
        int both = min_cnt + 1 - only_0 - only_1;
        if(start.next->val == ord[2])both--;
        if(end.prev->val == ord[2])both--;

/*        for(auto it = start.next;it != &end;it = it->next){
            cout << char('A' + it->val);
            }cout << endl;*/
        
        
        if(only_0 > only_1 + both){
            auto tmp = *pos[ord[2]][ord[0]][ord[2]].begin();
            remove(tmp);
            continue;
        }

        if(check(ord[2], ord[0], ord[1]))continue;
        if(check(ord[1], ord[0], ord[2]))continue;
        if(check(3, ord[0], ord[1]))continue;
        if(check(ord[1], ord[0], 3))continue;
        if(check(3, ord[0], ord[2]))continue;
        if(check(ord[2], ord[0], 3))continue;
        if(check(ord[1], ord[0], ord[1]))continue;
        if(n-- == 0)return -1;
    }

    for(auto it = start.next;it != &end;it = it->next){
        cout << char('A' + it->val);
    }cout << endl;

    
    return 0;
}

Measured memory_bytes: 80900