#include<bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 1e6 + 5;

int n;
char s[N], s1[N];

void shrink() {
	int t = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] ^ s[i - 1]) {
			s[++t] = s[i];
		}
	}
	n = t;
}

int cnt[3];
char pg[3], qg[3];
void trans() {
	for (int i = 1; i <= n; i++) {
		cnt[s[i] - 'A']++;
	}
	vector<pair<int, int>> a;
	a.emplace_back(cnt[0], 0);
	a.emplace_back(cnt[1], 1);
	a.emplace_back(cnt[2], 2);
	sort(a.begin(), a.end());
#define make_trans(x, y) pg[x] = y, qg[y] = x;
	for (int i = 0; i < 3; i++)
		make_trans(a[i].second, i);
	for (int i = 1; i <= n; i++) {
		s[i] = pg[s[i] - 'A'] + 'A';
	}
}

void make_valid() {
	int x = 0, y = 0;
	auto count = [&] (int l, int r) -> boolean {
		if (l > r) return false;
		for (int i = l; i <= r; i++) {
			if (s[i] == 'B') {
				x++;
				return false;
			}
		}
		if (l == 1 || r == n)
			return false;
		y++;
		return true;
	};
	int ls = 0;
	vector<int> pos;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'A') {
			if (count(ls + 1, i - 1) && ls) {
				pos.push_back(i);
			}
			ls = i;
		}
	}
	count(ls + 1, n);
	if (x < y) {
		int t = 0;
		pos.resize(y - x);
		reverse(pos.begin(), pos.end());
		for (int i = 1; i <= n; i++) {
			if (!pos.empty() && i == pos.back()) {
				pos.pop_back();
			} else {
				s[++t] = s[i];
			}
		}
		n = t;
		shrink();
		s[n + 1] = 0;
	}
	memset(cnt, 0, sizeof(cnt));
	for (int i = 1; i <= n; i++)
		cnt[s[i] - 'A']++;
	int d = cnt[2] - cnt[1];
	int t = 0;
	char target = 'C';
	(d < 0) && (d = -d, target = 'B');
	ls = 0;
	auto remove = [&] (int l, int r) {
		if (l > r)
			return;
		if ((l == 1 || r == n) || (l ^ r)) {
			if (s[l] == target && d) l++, d--;
			if (l < r && s[r] == target && d) r--, d--;
		}
		for (int i = l; i <= r; i++)
			s1[++t] = s[i];
	};
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'A') {
			remove(ls + 1, i - 1);
			s1[++t] = 'A';
			ls = i;
		}
	}
	remove(ls + 1, n);
	n = t;
	for (int i = 1; i <= n; i++) {
		s[i] = s1[i];
	}
	s[n + 1] = 0;
}

void make_equal() {
	memset(cnt, 0, sizeof(cnt));
	for (int i = 1; i <= n; i++)
		cnt[s[i] - 'A']++;
	assert(cnt[1] == cnt[2]);
	int d = cnt[1] - cnt[0];
	int t = 0;
	vector<pair<int, int>> pos;
	for (int i = 1; i <= n; i++) {
		if (i < n && d && s[i] != 'A' && s[i + 1] != 'A') {
			if (s1[t] == 'A' && s[i + 2] == 'A') {
				pos.emplace_back(t + 1, t + 2);
				s1[++t] = s[i];
			} else {
				i++, d--;
			}
		} else {
			s1[++t] = s[i];
		}
	}
	n = t;
	for (int i = 1; i <= n; i++)
		s[i] = s1[i];
	vector<int> delpos;
	for (int i = 0; i < d; i++) {
		delpos.push_back(pos[2 * i].first);
		delpos.push_back(pos[2 * i + 1].second);
	}
	t = 0;
	reverse(delpos.begin(), delpos.end());
	for (int i = 1; i <= n; i++) {
		if (!delpos.empty() && delpos.back() == i) {
			delpos.pop_back();
		} else {
			s[++t] = s[i];
		}
	}
	t = n;
	assert(delpos.empty());
}

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	shrink();
	trans();
	make_valid();
	make_equal();
	for (int i = 1; i <= n; i++)
		s[i] = qg[s[i] - 'A'] + 'A';
	s[n + 1] = 0;
	puts(s + 1);
	return 0;
}
