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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

char cs[]={'A','B','C'};

string encode(string T){
  int N=T.size();
  string sav=T;

  int cnt[]={0,0,0};
  rep(i,N){
    cnt[T[i]-'A']++;
  }
  int a=0;
  rep(j,3){
    if(cnt[a]>cnt[j])a=j;
  }
  if(a!=0)swap(cs[0],cs[a]);

  rep(i,N){
    T[i]=cs[T[i]-'A'];
  }

  int bcnt=0,ccnt=0;
  repl(i,1,N-1){
    if(T[i]=='B'&&T[i-1]=='A'&&T[i+1]=='A')bcnt++;
    if(T[i]=='C'&&T[i-1]=='A'&&T[i+1]=='A')ccnt++;
  }

  if(bcnt>ccnt){
    rep(b,3){
      if(cs[b]!='B')continue;
      rep(c,3){
        if(cs[c]!='C')continue;
        swap(cs[b],cs[c]);
        break;
      }
      break;
    }
  }

  T=sav;
  rep(i,N){
    T[i]=cs[T[i]-'A'];
  }

  return T;
}

string decode(string T){
  int N=T.size();
  rep(i,N){
    rep(j,3){
      if(T[i]==cs[j]){
        T[i]=(char)('A'+j);
        break;
      }
    }
  }
  return T;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  string S;
  cin>>S;
  N=S.size();

  {
    bool aru[]={false,false,false};
    rep(i,N){
      aru[S[i]-'A']=true;
    }
    rep(j,3){
      if(!aru[j]){
        cout<<""<<endl;
        return 0;
      }
    }
  }

  string T;

  char c='-';
  rep(i,N){
    if(c!=S[i]){
      T+=S[i];
      c=S[i];
    }
  }

  N=T.size();
  T=encode(T);

  int bcnt=0,ccnt=0;
  {
    int j=0;
    bool ok=false;
    while(j<N&&T[j]!='A'){
      if(T[j]=='B')ok=true;
      j++;
    }
    if(ok)bcnt++;
  }
  rep(i,N){
    if(i>0&&i-1<N&&T[i]=='C'&&T[i-1]=='A'&&T[i+1]=='A')ccnt++;
    if(T[i]=='A'){
      int j=i+1;
      bool ok=false;
      while(j<N&&T[j]!='A'){
        if(T[j]=='B')ok=true;
        j++;
      }
      if(ok)bcnt++;
    }
  }
  int rem=max(0,ccnt-bcnt);
  string res;
  rep(i,N-2){
    if(rem>0&&T[i]=='A'&&T[i+1]=='C'&&T[i+2]=='A'){
      rem--;
      continue;
    }
    res+=T[i];
  }
  res+=T[N-2]; res+=T[N-1];

  string resb;
  c='-';
  rep(i,res.size()){
    if(c!=res[i]){
      resb+=res[i];
      c=res[i];
    }
  }
  int acnt=0;
  bcnt=0; ccnt=0;
  N=resb.size();
  rep(i,N){
    if(resb[i]=='A')acnt++;
    if(resb[i]=='B')bcnt++;
    if(resb[i]=='C')ccnt++;
  }

  string resc;
  rep(i,N){
    if(ccnt>bcnt&&resb[i]=='C'&&!(i-1>=0&&i+1<N&&resb[i-1]==resb[i+1])){
      ccnt--;
      continue;
    }
    resc+=resb[i];
  }
  N=resc.size();

  string resd;
  rep(i,N){
    if(bcnt>ccnt&&resc[i]=='B'&&!(i-1>=0&&i+1<N&&resc[i-1]==resc[i+1])){
      bcnt--;
      continue;
    }
    resd+=resc[i];
  }
  N=resd.size();

  string rese;
  for(ll i=0;i<N-1;i++){
    if(bcnt>acnt&&((resd[i]=='B'&&resd[i+1]=='C')||(resd[i]=='C'&&resd[i+1]=='B'))&&!(rese.size()&&rese.back()=='A'&&i+2<N&&resd[i+2]=='A')){
      bcnt--; ccnt--;
      i++;
      continue;
    }
    rese+=resd[i];
  }
  rese+=resd[N-1];

  rese=decode(rese);
  cout<<rese<<endl;

  return 0;
}


Measured memory_bytes: 9160