#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
int n,pre[1000005],nxt[1000005];
char s[1000005];
bool flag[1000005];
vector<int>BAC,BAB,CAC,ABC,ABA,CBC,ACB,ACA,BCB;
void push(int i)
{
	if(!flag[i])return;
	if(i<1||i>n)return;
	if(s[i]=='A')
	{
		if(s[pre[i]]!=s[nxt[i]])BAC.push_back(i);
		else
		{
			if(s[pre[i]]=='B')BAB.push_back(i);
			else CAC.push_back(i);
		}
	}
	if(s[i]=='B')
	{
		if(s[pre[i]]!=s[nxt[i]])ABC.push_back(i);
		else
		{
			if(s[pre[i]]=='A')ABA.push_back(i);
			else CBC.push_back(i);
		}
	}
	if(s[i]=='C')
	{
		if(s[pre[i]]!=s[nxt[i]])ACB.push_back(i);
		else
		{
			if(s[pre[i]]=='A')ACA.push_back(i);
			else BCB.push_back(i);
		}
	}
}
int main()
{
	scanf("%s",s+1);
	n=(int)strlen(s+1);
	s[0]='D';
	for(int i=1;i<=n;i++)flag[i]=1;
	int last=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]==s[i-1])
		{
			flag[i]=0;
			continue;
		}
		pre[i]=last;
		nxt[last]=i;
		last=i;
	}
	nxt[last]=n+1;
	pre[n+1]=last;
	int a=0,b=0,c=0;
	for(int i=1;i<=n;i++)
	{
		if(!flag[i])continue;
		push(i);
		if(s[i]=='A')a++;
		if(s[i]=='B')b++;
		if(s[i]=='C')c++;
	}
	while(a!=b||a!=c)
	{
		if(a>=b&&a>=c)
		{
			while(!BAC.empty())
			{
				int node=BAC.back();
				if(flag[node]&&s[pre[node]]!=s[nxt[node]])break;
				BAC.pop_back();
			}
			if(!BAC.empty())
			{
				int node=BAC.back();
				BAC.pop_back();
				flag[node]=0;
				a--;
				pre[nxt[node]]=pre[node];
				nxt[pre[node]]=nxt[node];
				push(pre[node]);
				push(nxt[node]);
			}
			else
			{
				if(b>c)
				{
					while(!BAB.empty())
					{
						int node=BAB.back();
						if(flag[node]&&s[pre[node]]=='B'&&s[nxt[node]]=='B')break;
						BAB.pop_back();
					}
					if(!BAB.empty())
					{
						int node=BAB.back();
						BAB.pop_back();
						a--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
						node=pre[node];
						b--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
					}
					else
					{
						while(!CAC.empty())
						{
							int node=CAC.back();
							if(flag[node]&&s[pre[node]]=='C'&&s[nxt[node]]=='C')break;
							CAC.pop_back();
						}
						if(!CAC.empty())
						{
							int node=CAC.back();
							CAC.pop_back();
							a--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
							node=pre[node];
							c--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
						}
					}
				}
				else
				{
					while(!CAC.empty())
					{
						int node=CAC.back();
						if(flag[node]&&s[pre[node]]=='C'&&s[nxt[node]]=='C')break;
						CAC.pop_back();
					}
					if(!CAC.empty())
					{
						int node=CAC.back();
						CAC.pop_back();
						a--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
						node=pre[node];
						c--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
					}
					else
					{
						while(!BAB.empty())
						{
							int node=BAB.back();
							if(flag[node]&&s[pre[node]]=='B'&&s[nxt[node]]=='B')break;
							BAB.pop_back();
						}
						if(!BAB.empty())
						{
							int node=BAB.back();
							BAB.pop_back();
							a--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
							node=pre[node];
							b--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
						}
					}
				}
			}
		}
		else if(b>=a&&b>=c)
		{
			while(!ABC.empty())
			{
				int node=ABC.back();
				if(flag[node]&&s[pre[node]]!=s[nxt[node]])break;
				ABC.pop_back();
			}
			if(!ABC.empty())
			{
				int node=ABC.back();
				ABC.pop_back();
				flag[node]=0;
				b--;
				pre[nxt[node]]=pre[node];
				nxt[pre[node]]=nxt[node];
				push(pre[node]);
				push(nxt[node]);
			}
			else
			{
				if(a>c)
				{
					while(!ABA.empty())
					{
						int node=ABA.back();
						if(flag[node]&&s[pre[node]]=='A'&&s[nxt[node]]=='A')break;
						ABA.pop_back();
					}
					if(!ABA.empty())
					{
						int node=ABA.back();
						ABA.pop_back();
						b--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
						node=pre[node];
						a--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
					}
					else
					{
						while(!CBC.empty())
						{
							int node=CBC.back();
							if(flag[node]&&s[pre[node]]=='C'&&s[nxt[node]]=='C')break;
							CBC.pop_back();
						}
						if(!CBC.empty())
						{
							int node=CBC.back();
							CBC.pop_back();
							b--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
							node=pre[node];
							c--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
						}
					}
				}
				else
				{
					while(!CBC.empty())
					{
						int node=CBC.back();
						if(flag[node]&&s[pre[node]]=='C'&&s[nxt[node]]=='C')break;
						CBC.pop_back();
					}
					if(!CBC.empty())
					{
						int node=CBC.back();
						CBC.pop_back();
						b--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
						node=pre[node];
						c--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
					}
					else
					{
						while(!ABA.empty())
						{
							int node=ABA.back();
							if(flag[node]&&s[pre[node]]=='A'&&s[nxt[node]]=='A')break;
							ABA.pop_back();
						}
						if(!ABA.empty())
						{
							int node=ABA.back();
							ABA.pop_back();
							b--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
							node=pre[node];
							a--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
						}
					}
				}
			}
		}
		else if(c>=a&&c>=b)
		{
			while(!ACB.empty())
			{
				int node=ACB.back();
				if(flag[node]&&s[pre[node]]!=s[nxt[node]])break;
				ACB.pop_back();
			}
			if(!ACB.empty())
			{
				int node=ACB.back();
				ACB.pop_back();
				flag[node]=0;
				c--;
				pre[nxt[node]]=pre[node];
				nxt[pre[node]]=nxt[node];
				push(pre[node]);
				push(nxt[node]);
			}
			else
			{
				if(a>b)
				{
					while(!ACA.empty())
					{
						int node=ACA.back();
						if(flag[node]&&s[pre[node]]=='A'&&s[nxt[node]]=='A')break;
						ACA.pop_back();
					}
					if(!ACA.empty())
					{
						int node=ACA.back();
						ACA.pop_back();
						c--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
						node=pre[node];
						a--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
					}
					else
					{
						while(!BCB.empty())
						{
							int node=BCB.back();
							if(flag[node]&&s[pre[node]]=='B'&&s[nxt[node]]=='B')break;
							BCB.pop_back();
						}
						if(!BCB.empty())
						{
							int node=BCB.back();
							BCB.pop_back();
							c--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
							node=pre[node];
							b--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
						}
					}
				}
				else
				{
					while(!BCB.empty())
					{
						int node=BCB.back();
						if(flag[node]&&s[pre[node]]=='B'&&s[nxt[node]]=='B')break;
						BCB.pop_back();
					}
					if(!BCB.empty())
					{
						int node=BCB.back();
						BCB.pop_back();
						c--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
						node=pre[node];
						b--;
						flag[node]=0;
						pre[nxt[node]]=pre[node];
						nxt[pre[node]]=nxt[node];
						push(pre[node]);
						push(nxt[node]);
					}
					else
					{
						while(!ACA.empty())
						{
							int node=ACA.back();
							if(flag[node]&&s[pre[node]]=='A'&&s[nxt[node]]=='A')break;
							ACA.pop_back();
						}
						if(!ACA.empty())
						{
							int node=ACA.back();
							ACA.pop_back();
							c--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
							node=pre[node];
							a--;
							flag[node]=0;
							pre[nxt[node]]=pre[node];
							nxt[pre[node]]=nxt[node];
							push(pre[node]);
							push(nxt[node]);
						}
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	  if(flag[i])putchar(s[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 27104