#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
bool keep[1111111];

struct pci
{
	char cl,cr;
	int len;
	pci(char _cl='C', char _cr='C', int _len=0):cl(_cl),cr(_cr),len(_len){}
};

pci merge(pci a, pci b)
{
	if(b.len==0) return a;
	if(a.len==0) return b;
	pci c;
	c.len=a.len+b.len;
	if(a.cr==b.cl) c.len--;
	c.cl=a.cl; c.cr=b.cr;
	return c;
}

string solve(string s)
{
	int n=s.length();
	int c[3]={0,0,0};
	for(int i=0;i<n;i++)
	{
		c[s[i]-'A']++;
	}
	//cerr<<c[0]<<' '<<c[1]<<' '<<c[2]<<'\n';
	string t;
	t="A"+s+"A";
	vi pos;
	for(int i=0;i<t.length();i++)
	{
		if(t[i]=='A') 
		{
			pos.pb(i); 
		}
	}
	vector<pair<pci,int> > V;
	vi before;
	for(int i=0;i+1<pos.size();i++)
	{
		int l=pos[i]+1; int r=pos[i+1]-1;
		before.pb(pos[i]-1); //check later
		int len=r-l+1;
		if(len==0) V.pb({pci('C','C',0),0});
		else V.pb({pci(t[l],t[r],len),0});
		if(i==0||i+2==pos.size()) V[i].se=1;
	}
	////cerr<<s<<'\n';
	for(auto &Y:V)
	{
		auto X = Y.fi;
		////cerr<<X.cl<<' '<<X.cr<<' '<<X.len<<'\n';
	}
	if(c[1]>c[2])
	{
		for(auto &Y:V)
		{
			if(c[1]<=c[2]) break;
			auto &X = Y.fi;
			if(Y.se==0&&X.len<=1) continue;
			if(X.len==0) continue;
			if(X.len==1)
			{
				if(X.cl=='B')
				{
					X.len=0; c[1]--; continue;
				}
			}
			else
			{
				if(X.cl=='B')
				{
					X.len--; X.cl='C'; c[1]--;
				}
				if(c[1]<=c[2]) break;
				if(X.cr=='B')
				{
					X.len--; X.cr='C'; c[1]--;
				}
			}
		}
	}
	if(c[1]<c[2])
	{
		for(auto &Y:V)
		{
			if(c[1]>=c[2]) break;
			auto &X = Y.fi;
			if(Y.se==0&&X.len<=1) continue;
			if(X.len==0) continue;
			if(X.len==1)
			{
				if(X.cl=='C')
				{
					X.len=0; c[2]--; continue;
				}
			}
			else
			{
				if(X.cl=='C')
				{
					X.len--; X.cl='B'; c[2]--;
				}
				if(c[2]<=c[1]) break;
				if(X.cr=='C')
				{
					X.len--; X.cr='B'; c[2]--;
				}
			}
		}
	}
	assert(c[1]==c[2]);
	for(auto &Y:V)
	{
		auto X = Y.fi;
		////cerr<<X.cl<<' '<<X.cr<<' '<<X.len<<'\n';
	}
	for(auto &Y:V)
	{
		if(c[1]<=c[0]) break;
		auto &X = Y.fi;
		while(c[1]>c[0])
		{
			if(X.len>2)
			{
				X.len-=2; c[1]--;
			}
			else if(X.len==2&&Y.se==1)
			{
				X.len-=2; c[1]--;
			}
			else break;
		}
	}
	for(auto &Y:V)
	{
		auto X = Y.fi;
		////cerr<<X.cl<<' '<<X.cr<<' '<<X.len<<'\n';
	}
	string ans;
	for(int i=0;i<V.size();i++)
	{
		pci tmp = V[i].fi;
		char cur = tmp.cl;
		for(int j=0;j<tmp.len;j++)
		{
			ans+=cur;
			if(cur=='B') cur='C';
			else cur='B';
		}
		if(i+1<V.size()) ans+="A";
	}
	////cerr<<ans<<'\n';
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//freopen("abc-string.txt","r",stdin);
	string s; cin>>s;
	int a[3]={0,0,0};
	//do compression
	string t;
	for(int i=0;i<s.length();i++)
	{
		if(i>0&&s[i]==s[i-1]) continue;
		t+=s[i];
	}
	s=t;
	int n=s.length();
	for(int i=0;i<n;i++) a[s[i]-'A']++;
	//make A the one with least occurrence
	//////cerr<<s<<'\n';
	//////cerr<<a[0]<<' '<<a[1]<<' '<<a[2]<<'\n';
	int minc=int(1e9); char C = 'A';
	for(int i=0;i<3;i++)
	{
		if(a[i]<minc)
		{
			minc=a[i]; C='A'+i;
		}
	}
	//swap 'A' with C
	for(int i=0;i<n;i++)
	{
		if(s[i]=='A')
		{
			s[i]=C;
		}
		else if(s[i]==C)
		{
			s[i]='A';
		}
	}
	//now A has the least occurrence
	//phase 2: find the As
	int u[2] = {0,0};
	int g[2] = {0,0};
	////cerr<<s<<'\n';
	t="A"+s+"A";
	vi pos;
	for(int i=0;i<t.length();i++)
	{
		if(t[i]=='A') 
		{
			pos.pb(i);
			if(i>0&&i+1<t.length()) keep[i-1]=1;
		}
	}
	vector<pci> V;
	vi before;
	for(int i=0;i+1<pos.size();i++)
	{
		int l=pos[i]+1; int r=pos[i+1]-1;
		before.pb(pos[i]-1); //check later
		////cerr<<before[i]<<'\n';
		int len=r-l+1;
		if(len==0) V.pb(pci('C','C',0));
		else V.pb(pci(t[l],t[r],len));
		if(l>r) continue;
		if(l==r&&i>0&&i+2<pos.size())
		{
			u[t[l]-'B']++;
		}
		int E[2]={0,0};
		for(int j=l;j<=r;j++)
		{
			E[t[j]-'B']++;
		}
		for(int j=0;j<2;j++)
		{
			g[j]+=(E[j]>0?1:0);
		}
	}
	////cerr<<s<<'\n';
	for(auto &Y:V)
	{
		////cerr<<Y.cl<<' '<<Y.cr<<' '<<Y.len<<'\n';
	}
	//////cerr<<u[0]<<' '<<u[1]<<' '<<g[0]<<' '<<g[1]<<'\n';
	if(u[0]>g[1])
	{
		int del = u[0]-g[1];
		pci cur=V[0];
		for(int i=1;i<V.size();i++)
		{
			if(del==0) break ;
			if(V[i].len==1&&V[i].cl=='B')
			{
				del--;
				cur=merge(cur,V[i]);
				keep[before[i]]=0;
			}
			else
			{
				cur=V[i];
			}
		}
	}
	if(u[1]>g[0])
	{
		int del = u[1]-g[0];
		pci cur=V[0];
		for(int i=1;i<V.size();i++)
		{
			if(del==0) break ;
			if(V[i].len==1&&V[i].cl=='C')
			{
				del--;
				cur=merge(cur,V[i]);
				keep[before[i]]=0;
			}
			else
			{
				cur=V[i];
			}
		}
	}
	t="";
	for(int i=0;i<n;i++)
	{
		if(s[i]=='A'&&!keep[i]) continue;
		t+=s[i];
	}
	s=t;t="";
	for(int i=0;i<s.length();i++)
	{
		if(i>0&&s[i]==s[i-1]) continue;
		t+=s[i];
	}
	s=t;
	//solve the problem on this new s!
	s = solve(s);
	for(int i=0;i<s.length();i++)
	{
		if(s[i]==C)
		{
			s[i]='A';
		}
		else if(s[i]=='A')
		{
			s[i]=C;
		}
	}
	int CC[3]={0,0,0};
	for(int i=0;i<s.length();i++) CC[s[i]-'A']++;
	//for(int j=0;j<3;j++) cerr<<CC[j]<<' ';
	//cerr<<'\n';
	cout<<s<<'\n';
}


Measured memory_bytes: 23152