#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'C'; c = gc()) ;
		for(; c >= 'A' && c <= 'C'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e6+5; 
char s[N];
int _cnt[3],rnk[3],cnt[3],_rnk[N];
inline bool cmp(ri x,ri y){
	return _cnt[x]<_cnt[y];
}
int main(){
	ri n,m,i,k0,k1;
	read(s);
	n=strlen(s+1);
	m=0;
	for(i=1;i<=n;++i)
		if(s[i]!=s[i-1])
			s[++m]=s[i];
	s[m+1]='\0';
	n=m;
	for(i=1;i<=n;++i)
		++_cnt[s[i]-='A'];
//	printf("n = %d cnt %d %d %d\n",n,_cnt[0],_cnt[1],_cnt[2]);
//	for(i=1;i<=n;++i) printf("%c",s[i]+'A');
//	puts("");
	iota(rnk,rnk+3,0);
	sort(rnk,rnk+3,cmp);
//	for(i=0;i<3;++i) printf("%d ",rnk[i]);
//	puts("");
	for(i=0;i<3;++i) _rnk[rnk[i]]=i;
	for(i=1;i<=n;++i) s[i]=_rnk[s[i]],cnt[s[i]]=_cnt[rnk[s[i]]];
//	printf("n = %d cnt %d %d %d\n",n,cnt[0],cnt[1],cnt[2]);
//	for(i=1;i<=n;++i) printf("%c",s[i]+'A');
//	puts("");
	// delete(C)
	m=0;
	for(i=1;i<=n&&cnt[1]!=cnt[2];++i)
		if(s[i]==2&&(m==0||i==n||s[m]!=s[i+1]))
			--cnt[2];
		else
			s[++m]=s[i];
	for(;i<=n;++i) s[++m]=s[i];
	s[m+1]='\0';
	n=m;
//	printf("n = %d cnt %d %d %d\n",n,cnt[0],cnt[1],cnt[2]);
//	for(i=1;i<=n;++i) printf("%c",s[i]+'A');
//	puts("");
	// delete(BC/CB)
	m=0;
	for(i=1;i+1<=n&&cnt[0]!=cnt[1];++i)
		if((s[i]==1&&s[i+1]==2||s[i]==2&&s[i+1]==1)&&(m==0||i+1==n||s[m]!=s[i+2]))
			--cnt[1],--cnt[2],++i;
		else
			s[++m]=s[i]; 
	for(;i<=n;++i) s[++m]=s[i];
	s[m+1]='\0';
	n=m;
//	printf("n = %d cnt %d %d %d\n",n,cnt[0],cnt[1],cnt[2]);
//	for(i=1;i<=n;++i) printf("%c",s[i]+'A');
//	puts("");
	// delete(AB/BA/AC/CA)
	m=0;k0=k1=cnt[2]-cnt[0];
	for(i=1;i+1<=n;++i){
		if(s[i]==0&&s[i+1]==2||s[i]==2&&s[i+1]==0){
			if(k0&&(m==0||i+1==n||s[m]!=s[i+2]))
				--k0,--cnt[0],--cnt[2],++i;
			else
				s[++m]=s[i];
		}
		else if(s[i]==1&&s[i+1]==2||s[i]==2&&s[i+1]==1){
			if(k1&&(m==0||i+1==n||s[m]!=s[i+2]))
				--k1,--cnt[1],--cnt[2],++i;
			else
				s[++m]=s[i];
		}
		else
			s[++m]=s[i];
	}
	for(;i<=n;++i) s[++m]=s[i];
	s[m+1]='\0';
	n=m;
//	printf("n = %d cnt %d %d %d\n",n,cnt[0],cnt[1],cnt[2]);
//	for(i=1;i<=n;++i) printf("%c",s[i]+'A');
//	puts("");
	for(i=1;i<=n;++i) putc(rnk[s[i]]+'A');
	putc('\n');
	return 0;
}

Measured memory_bytes: 7424