#include <cstdio>
#include <cstring>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
inline char nc()
{
    static char buf[100000], *l = buf, *r = buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x = 0; int f = 1, ch = nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x *= f;
}
const int maxn = 1e6 + 5;
int n;
char s[maxn];
int b1, b2, c1, c2;
char idx[256];
void Unique()
{
    int m = 0;
    for(int i = 0; i < n; ++i)
    {
        if(i == 0 || s[i] != s[i - 1]) s[m++] = s[i];
    }
    n = m;
}
void Swap(char a, char b)
{
    swap(idx[a - 'A'], idx[b - 'A']);
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == a) {s[i] = b; continue;}
        if(s[i] == b) {s[i] = a; continue;}
    }
}
void update(int l, int r)
{
    if(l > r) return;
    bool fb = 0, fc = 0;
    for(int i = l; i <= r; ++i)
    {
        if(s[i] == 'B') fb = 1;
        if(s[i] == 'C') fc = 1;
    }
    if(fb) {++b1; if(l == r) ++b2;}
    if(fc) {++c1; if(l == r) ++c2;}
}
void solve()
{
    Unique();
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'A') ++a;
        if(s[i] == 'B') ++b;
        if(s[i] == 'C') ++c;
    }
    if(a > b) Swap('A', 'B'), swap(a, b);
    if(a > c) Swap('A', 'C'), swap(a, c);
    if(a == 0) {n = 0; return;}
    int las = -1;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'A')
        {
            update(las + 1, i - 1);
            las = i;
        }
    }
    update(las + 1, n - 1);
    if(c2 > b1 || b2 > c1)
    {
        if(c2 > b1)
        {
            swap(b1, c1);
            swap(b2, c2);
            Swap('B', 'C');
        }
        int m = 0;
        int l = 0;     if(b2 > c1 && s[l] == 'B' && s[l + 1] == 'A') ++l, --b2;
        int r = n - 1; if(b2 > c1 && s[r] == 'B' && s[r - 1] == 'A') --r, --b2;
        for(int i = l; i <= r; ++i)
        {
            if(b2 > c1 && (m == 0 || s[m - 1] == 'A') && s[i] == 'B' && (i == n - 1 || s[i + 1] == 'A'))
            {
                --b2, ++i;
                continue;
            }
            s[m++] = s[i];
        }
        n = m;
        if(b2 > c1) {n = 0; return;}
        Unique();
    }
    // print();
    int p = 0, q = 0, r = 0;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'A') ++p;
        if(s[i] == 'B') ++q;
        if(s[i] == 'C') ++r;
    }
    if(q > r) {Swap('B', 'C'), swap(q, r);}
    int m = 0;
    for(int i = 0; i < n; ++i)
    {
        if(q < r && s[i] == 'C' && (m == 0 || i == n - 1 || s[m - 1] != s[i + 1]))
        {
            --r;
            continue;
        }
        s[m++] = s[i];
    }
    n = m;
    // print();
    m = 0;
    for(int i = 0, f = 1; i < n - 1; ++i)
    {
        if(s[i] == 'A') f = 0;
        if(q > p && (f || i == n - 2 || s[i + 2] != 'A'))
        {
            if((s[i] == 'B' && s[i + 1] == 'C') || (s[i] == 'C' && s[i + 1] == 'B'))
            {
                --q;
                ++i;
                continue;
            }
        }
        s[m++] = s[i];
    }
    s[m++] = s[n - 1];
    n = m;
}
int main()
{
    // freopen("E.in", "r", stdin);
    // freopen("E.out", "w", stdout);
    idx[0] = 'A';
    idx[1] = 'B';
    idx[2] = 'C';
    scanf("%s", s);
    n = strlen(s);
    solve();
    for(int i = 0; i < n; ++i)
    {
        printf("%c", idx[s[i] - 'A']);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2176