#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (5000010)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
int n,c1,c2,c3,p1,p2,q1,q2,now,tar;
char s[N],str[N],w1,w2,w3;
vector<int> pos2; bool ban[N];
int gs(int x){
	if(s[x]==w1)return 1;else if(s[x]==w2)return 2;else return 3;
}
void getstr(int L,int R){
	if(L>R)return;
	int ch[4]={0,0,0,0};
	for(int i=L;i<=R;i++)ch[gs(i)]++;
	if(!ch[2]&&L>1&&R<n)q2++,pos2.push_back(L-1);
	if(!ch[3]&&L>1&&R<n)p2++;
	if(ch[2])p1++; if(ch[3])q1++;
}
void del(){
	int tmp=0,lst=-1;
	for(int i=1;i<=n;i++)
	if(!ban[i]&&s[i]!=lst)lst=s[i],s[++tmp]=s[i];
	n=tmp;
}
void cal(){
	c1=c2=c3=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)c1++;else if(s[i]==w2)c2++;else c3++;
	memset(ban,0,sizeof(ban));
}
void solve(int L,int R){
	if(L>R)return;
	if(L==R){
		if(L==1||L==n){if(s[L]==w3&&c3>c2)c3--,ban[L]=1;}
		return;
	}
	if(s[L]==w3&&c3>c2)c3--,ban[L]=1;
	if(s[R]==w3&&c3>c2)c3--,ban[R]=1;
}
void solve2(int L,int R){
	if(L>R)return;
	while(L<R&&now>tar){
		if(L+1>=R&&L!=1&&R!=n)break;
		now--,ban[L]=ban[L+1]=1,L+=2;
	}
}
void Print(){
	for(int i=1;i<=n;i++)putchar(s[i]); puts("");
}
int main(){
	scanf("%s",str+1),w1='A',w2='B',w3='C';
	for(int i=1;i<=strlen(str+1);i++)
	if(str[i]!=str[i-1]){
		s[++n]=str[i];
		if(s[n]==w1)c1++;else if(s[n]==w2)c2++;else c3++;
	}
	if(c1>c2)swap(c1,c2),swap(w1,w2);
	if(c1>c3)swap(c1,c3),swap(w1,w3);
	if(c2>c3)swap(c2,c3),swap(w2,w3);
//	cout<<w1<<" "<<w2<<" "<<w3<<endl;
	int j=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)getstr(j+1,i-1),j=i; getstr(j+1,n);
	if(p1<q2)for(int i=0;i<q2-p1;i++)ban[pos2[i]]=1,c1--;
//	Print();
	del(),cal(),j=0;
	for(int i=1;i<=n;i++)
	if(s[i]==w1)solve(j+1,i-1),j=i; solve(j+1,n);
	del(),cal(),j=0,now=c2,tar=c1;
//	Print();
	for(int i=1;i<=n;i++)
	if(s[i]==w1)solve2(j+1,i-1),j=i; solve2(j+1,n);
	for(int i=1;i<=n;i++)
	if(!ban[i])printf("%c",s[i]);
}