// Tenshi ni Fureta yo!

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<typename T> inline T sqr(const T &val) { return val * val; }

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return *(cur == ed ? ed = buffer + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur = buffer : cur)++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

// END tpl.

inline void read_str(char *s)
{
	register char ch(getc());
	while(!isgraph(ch)) ch = getc();
	for(; isgraph(ch); ch = getc()) *s++ = ch;
	*s = '\0';
}

const int MAXN = (int) 1e6;

int n;

char s[MAXN + 5];

inline void input()
{
	read_str(s + 1), n = strlen(s + 1);
}

inline void solve()
{
	n = unique(s + 1, s + n + 1) - s - 1;

	static int A[MAXN + 5];
	for(int i = 1; i <= n; ++i) A[i] = s[i] - 'A';

	static int prv[MAXN + 5], nxt[MAXN + 5], cut[MAXN + 5], head;

	head = 1;
	for(int i = 1; i <= n; ++i)
	{
		prv[i] = i - 1;
		nxt[i] = i == n  ? 0 : i + 1;
	}
	A[0] = -1;
	A[n + 1] = -2;
	cut[0] = cut[n + 1] = 1;

	auto erase = [&] (int u)
	{
		if(u == head) head = nxt[head];
		if(u[prv]) u[prv][nxt] = u[nxt];
		if(u[nxt]) u[nxt][prv] = u[prv];
		cut[u] = 1;
	};

	int cnt[3] = {0, 0, 0}, ids[3], rnk[3];
	for(int i = 1; i <= n; ++i) ++cnt[A[i]];
	for(int i = 0; i < 3; ++i) ids[i] = i;

	sort(ids, ids + 3, [&] (int x, int y) { return cnt[x] < cnt[y]; });
	for(int i = 0; i < 3; ++i) rnk[ids[i]] = i;

	sort(cnt, cnt + 3);
	for(int i = 1; i <= n; ++i) A[i] = rnk[A[i]];

	for(int i = head; cnt[2] > cnt[1] && i; i = i[nxt]) if(A[i] == 2)
		if(A[i[prv]] != A[i[nxt]]) erase(i), --cnt[A[i]];

	for(int i = head; cnt[2] > cnt[1] && i; )
	{
		int x = i, y = x[nxt], z = y[nxt];
		if(x && y && z && A[x] == 0 && A[y] == 2 && A[z] == 0)
		{
			erase(y), --cnt[A[y]];
			erase(z), --cnt[A[z]];
		}
		else i = i[nxt];
	}

	for(int i = head; i && i[nxt]; ) if(i[nxt])
	{
		int p = i, q = i[nxt];
		if(A[p] != A[q] && cnt[A[p]] > cnt[0] && cnt[A[q]] > cnt[0] && A[p[prv]] != A[q[nxt]])
		{
			i = q[nxt];
			erase(p), --cnt[A[p]];
			erase(q), --cnt[A[q]];
		}
		else i = i[nxt];
	}

	if(cnt[0] == cnt[1] && cnt[1] == cnt[2])
	{
		for(int i = head; i; i = i[nxt]) putchar('A' + ids[A[i]]);
		puts("");
	}
	else puts("");
}

int main()
{
#ifdef K_ON
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}




Measured memory_bytes: 17280