//2019.7.22 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
#define Pi 2.0*acos(-1.0)
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG __int128 x){
//    if(x>10)write(x/10);
//    putchar(x%10+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=1e6+10;
namespace MAIN{
    char str[N],qc[N];
    int n;
    int buc[3+10];
    typedef pair<int,char> pii;
    pii A[3];
    string S,T;
    vector<string> vec;
    inline void MAIN(){
        scanf("%s",str+1),n=int(strlen(str+1));
        res nw=0;
        for(res i=1;i<=n;i++)if(!nw||str[i]!=qc[nw])qc[++nw]=str[i],buc[str[i]-'A']++;
        n=nw,A[0]=mp(buc[0],'A'),A[1]=mp(buc[1],'B'),A[2]=mp(buc[2],'C'),sort(A,A+3);
        for(res i=0;i<=2;i++)buc[i]=A[i].fi;
        for(res i=1;i<=n;i++)str[i]=qc[i];
        for(res i=1;i<=n;i++)
            for(res p=0;p<=2;p++)
                if(str[i]==A[p].se){str[i]=char('A'+p);break;}
        for(res i=1;i<=n;i++)S.pb(str[i]);
        res cur=0;
        while(cur<n){
            if(S[cur]=='C'){
                if(buc[2]>buc[1])buc[2]--;
                else vec.pb(S.substr(cur,1));
                cur++;
            }
            else if(S[cur]=='A'){
                vec.pb(S.substr(cur,1)),cur++;
                while(cur+2<=n&&S[cur]=='C'&&S[cur+1]=='A')vec.back().pb('C'),vec.back().pb('A'),cur+=2;
            }
            else{
                vec.pb(S.substr(cur,1)),cur++;
                while(cur+2<=n&&S[cur]=='C'&&S[cur+1]=='B')vec.back().pb('C'),vec.back().pb('B'),cur+=2;
            }
        }
        for(auto &x:vec)while(x[0]=='A'&&buc[2]>buc[1]&&x.size()>=3)x.pop_back(),x.pop_back(),buc[0]--,buc[2]--;
        S.clear();
        for(auto x:vec)S+=x;
        T.clear(),cur=0;
        while(cur<S.size()){
            if(buc[1]>buc[0]&&cur+3<=S.size()&&((S[cur]=='B'&&S[cur+1]=='C'&&S[cur+2]=='B')||(S[cur]=='C'&&S[cur+1]=='B'&&S[cur+2]=='C')))cur+=2,buc[1]--,buc[2]--;
            else if(buc[1]>buc[0]&&cur+2==S.size()&&((S[cur]=='B'&&S[cur+1]=='C')||(S[cur]=='C'&&S[cur+1]=='B')))cur+=2,buc[1]--,buc[2]--;
            else T.pb(S[cur]),cur++;
        }
//        cout<<T<<endl;
        for(auto x:T)printf("%c",A[x-'A'].se);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}


Measured memory_bytes: 60788