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

int n, n2, pre[1001000], nex[1001000], die[1001000];
char s[1001000], s2[1001000];

queue<int>q[257];

int encode(int *tmp){
    int res=0;
    for (int i=0;i<4;++i){
        res|= tmp[i]<<i*2; 
    }
    return res;
}

int gao(int sp,int w=1){
    static int tmp[4];
    tmp[w]=sp;
    {
        int p=sp;
        for (int i=w-1;i>=0;--i)
            tmp[i]=p=pre[p];
    }
    {
        int p=sp;
        for (int i=w+1;i<4;++i)
            tmp[i]=p=nex[p];
    }
    if (tmp[1]==0||tmp[2]==n+1||die[sp]) return -1;
    for (int i=0;i<4;++i) tmp[i]=s[tmp[i]];
    return encode(tmp);
}

void decode(int *tmp,int val){
    for (int i=0;i<4;++i)
        tmp[i]=val>>i*2&3;
}

int fix(int v){
    while (q[v].size()){
        int p=q[v].front();
        if (gao(p)==v) break;
        q[v].pop();
    }
    return q[v].size();
}

void fuck(int p0){
    for (int T=3;T--;){
        int t=gao(nex[p0]);
        if (t!=-1) q[t].push(nex[p0]);
        p0=pre[p0];
    }
}

int cnt[4];

void era(int p){
    // printf("   era %d\n",p);
    die[p]=1; --cnt[s[p]];
    nex[pre[p]]=nex[p];
    pre[nex[p]]=pre[p];
}

int main(){
    cin>>s2+1; n2=strlen(s2+1);
    for (int i=1;i<=n2;++i)
        if (s2[i]!=s2[i-1]){
            s[++n]=s2[i];
        }
    for (int i=1;i<=n;++i){
        s[i]-='A'-1;
        ++cnt[s[i]];
    }
    if (!cnt[1]||!cnt[2]||!cnt[3]){
        puts(""); return 0;
    }
    for (int i=1;i<=n+1;++i)
        pre[i]=i-1, nex[i-1]=i;
    pre[0]=0; nex[n+1]=n+1;
    for (int i=1;i<n;++i)
        q[gao(i)].push(i);
    while (1){
        if (cnt[1]==cnt[2]&&cnt[2]==cnt[3]) break;
        int id[4]; id[1]=1; id[2]=2; id[3]=3;
        sort(id+1,id+4,[=](int i,int j){return cnt[i]>cnt[j];});
        
        if (cnt[id[1]]==cnt[id[2]]) goto shit;
        
        for (int e=0;e<=3;++e)
            for (int a=0;a<=3;++a)
                for (int b=0;b<=3;++b){
                    if (a==b&&a!=0) continue;
                    {
                        int tmp[4]={e,a,id[1],b}; int en=encode(tmp);
                        if (fix(en)){
                            int p1=q[en].front(), p2=nex[p1], p0=pre[p1]; q[en].pop();
                            era(p2); fuck(p1);
                            goto flag;
                        }
                    }
                    {
                        int tmp[4]={a,id[1],b,e}; int en=encode(tmp);
                        if (fix(en)){
                            int p1=q[en].front(), p2=nex[p1], p0=pre[p1]; q[en].pop();
                            era(p1); fuck(p0);
                            goto flag;
                        }
                    }
                }

        shit:;

        for (int a=0;a<=3;++a)
            for (int b=0;b<=3;++b){
                if (a==b&&a!=0) continue;
                {
                    int tmp[4]={a,id[1],id[2],b}; int en=encode(tmp);
                    if (fix(en)){
                        int p1=q[en].front(), p2=nex[p1], p0=pre[p1]; q[en].pop();
                        era(p1); era(p2); fuck(p0);
                        goto flag;
                    }
                }
                {
                    int tmp[4]={a,id[2],id[1],b}; int en=encode(tmp);
                    if (fix(en)){
                        int p1=q[en].front(), p2=nex[p1], p0=pre[p1]; q[en].pop();
                        era(p1); era(p2); fuck(p0);
                        goto flag;
                    }
                }
            }

        for (int e=0;e<=3;++e)
            for (int a=0;a<=3;++a)
                for (int b=0;b<=3;++b){
                    if (a==b&&a!=0) continue;
                    {
                        int tmp[4]={e,a,id[1],b}; int en=encode(tmp);
                        if (fix(en)){
                            int p1=q[en].front(), p2=nex[p1], p0=pre[p1]; q[en].pop();
                            era(p2); fuck(p1);
                            goto flag;
                        }
                    }
                    {
                        int tmp[4]={a,id[1],b,e}; int en=encode(tmp);
                        if (fix(en)){
                            int p1=q[en].front(), p2=nex[p1], p0=pre[p1]; q[en].pop();
                            era(p1); fuck(p0);
                            goto flag;
                        }
                    }
                }

        puts(""); return 0;
        flag:;
        

        // for (int i=1;i<=n;++i) if (!die[i]) putchar(s[i]+'A'-1);
        // puts("");
        // printf(" %d %d %d\n",cnt[1],cnt[2],cnt[3]);
    }
    for (int i=1;i<=n;++i) if (!die[i]) putchar(s[i]+'A'-1);
    puts("");
}

Measured memory_bytes: 22400