#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = 2e6;

int cnt[3];
vector <int> ok[3][3];

int lf[N], rf[N];

int get_lf(int i) {
  if (i == -1) return -1;
  if (lf[i] == i) {
    return lf[i];
  } else {
    return lf[i] = get_lf(lf[i]);
  }
}

int get_rf(int i) {
  if (rf[i] == i) {
    return rf[i];
  } else {
    return rf[i] = get_rf(rf[i]);
  }
}

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  auto longest = [&] (string s) {
    int n = (int) s.size();
    vector <int> dp(n);
    vector <int> last(3, -1);
    for (auto &c : s) {
      if (c == 'A') c = 0;
      else if (c == 'B') c = 1;
      else c = 2;
    }
    for (int i = n - 1; i >= 0; i--) {
      for (int t = 0; t < 3; t++) {
        if (t != s[i] && last[t] != -1) {
          dp[i] = max(dp[i], dp[last[t]]);
        }
      }
      dp[i]++;
      last[s[i]] = i;
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
      mx = max(mx, dp[i]);
    }
    int lst = -1;
    string rest = "";
    for (int i = 0; i < n; i++) {
      if (s[i] != lst && dp[i] == mx) {
        mx--;
        lst = s[i];
        rest += s[i] + 'A';
      }
    }
    return rest;
  };
  auto flex = [&] (string s) {
    vector <int> cnt(3);
    for (auto &c : s) {
      if (c == 'A') c=  0;
      else if (c == 'B') c = 1;
      else c = 2;
    }
    for (auto c : s) {
      cnt[c]++;
    }
    while (cnt[0] != cnt[1] || cnt[0] != cnt[2]) {
      /*
      string t = s;
      for (auto &c : t) c += 'A';
      cout << t << endl;
      */
      int x = 0;
      int y= -1;
      int mn = 0;
      for (int i = 0; i < 3; i++) {
        if (cnt[i] < cnt[mn]) {
          mn = i;
        }
        if (cnt[i] > cnt[x]) {
          x = i;
          y = -1;
        } else if (cnt[i] == cnt[x]) {
          y = i;
        }
      }
      bool good = false;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          if (i == x && j == y) {
            for (int it = 0; it + 1 < (int) s.size(); it++) {
              if (s[it] == i && s[it + 1] == j && (it == 0 || it + 1 == (int) s.size() - 1 || s[it - 1] != s[it + 2])) {
                cnt[i]--, cnt[j]--;
                s.erase(s.begin() + it);
                s.erase(s.begin() + it);
                good = true;
                break;
              }
            }
            if (good) {
              i = 3;
              break;
            }
          }
        }
      }
      if (good) continue;
      for (int i = 0; i < 3; i++) {
        if (i == x || i == y) {
          for (int j = 0; j < (int) s.size(); j++) {
            if (s[j] == i && (j == 0 || j == (int) s.size() - 1 || s[j - 1] != s[j + 1])) {
              s.erase(s.begin() + j);
              cnt[i]--;
              good = true;
              break;
            }
          }
          if (good) break;
        }
      }
      if (good) continue;
      for (int i = 0; i < 3; i++) {
        if (i != mn) {
          for (int j = 0; j < (int) s.size(); j++) {
            if (s[j] == i && (j == 0 || j == (int) s.size() - 1 || s[j - 1] != s[j + 1])) {
              s.erase(s.begin() + j);
              cnt[i]--;
              good = true;
              break;
            }
          }
          if (good) break;
        }
      }
      if (good) continue;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          if (i != mn && j != mn) {
            for (int it = 0; it + 1 < (int) s.size(); it++) {
              if (s[it] == i && s[it + 1] == j && (it == 0 || it + 1 == (int) s.size() - 1 || s[it - 1] != s[it + 2])) {
                cnt[i]--, cnt[j]--;
                s.erase(s.begin() + it);
                s.erase(s.begin() + it);
                good = true;
                break;
              }
            }
            if (good) {
              i = 3;
              break;
            }
          }
        }
      }
      if (!good) {
        cout << s << endl;
        exit(0);
      }
    }
    for (auto &c : s) c += 'A';
    return s;
  };
  auto fast = [&] (string s) {
    int n = (int) s.size();
    for (int i = 0; i < n; i++) {
      lf[i] = rf[i] = i;
    }
    rf[n] = n;
    lf[n] = n;
    for (auto &c : s) {
      if (c == 'A') c = 0;
      else if (c == 'B') c = 1;
      else c = 2;
    }
    for (int i = 0; i < 3; i++) {
      cnt[i] = 0;
      for (int j = 0; j < 3; j++) {
        ok[i][j].clear();
      }
    }
    for (int i = 0; i < (int) s.size(); i++) {
      cnt[s[i]]++;
      if (!i || (i == (int) s.size() - 1) || s[i - 1] != s[i + 1]) {
        ok[s[i]][s[i]].push_back(i);
      }
      if (i + 1 < (int) s.size() && (!i || i == (int) s.size() - 2 || s[i - 1] != s[i + 2])) {
        ok[s[i]][s[i + 1]].push_back(i);
      }
    }
    auto prv = [&] (int i) {
      return get_lf(i - 1);
      /*
      auto it = q.find(i);
      if (it != q.begin()) {
        it--;
        return *it;
      } else {
        return -1;
      }
      */
    };
    auto nxt = [&] (int i) {
      int go = get_rf(i + 1);
      if (go == n) return -1;
      return go;
      /*
      auto it = q.find(i);
      if (next(it) != q.end()) {
        it++;
        return *it;
      } else {
        return -1;
      }
      */
    };
    vector <bool> died(n);
    auto good_one = [&] (int i) {
      if (died[i]) return false;
      int l = prv(i), r = nxt(i);
      return (l == -1 || r == -1 || s[l] != s[r]);
    };
    auto good_two = [&] (int i) {
      if (died[i]) return false;
      int l = prv(i), r = nxt(i);
      if (r == -1) return false;
      int tr = nxt(r);
      return (l == -1 || tr == -1 || s[l] != s[tr]);
    };
    auto relax = [&] (int i) {
      if (good_one(i)) {
        ok[s[i]][s[i]].push_back(i);
      }
      if (good_two(i)) {
        ok[s[i]][s[nxt(i)]].push_back(i);
      }
    };
    auto del = [&] (int i) {
      died[i] = true;
      vector <int> guys;
      int me = i;
      for (int jt = 0; jt < 2; jt++) {
        me = prv(me);
        if (me == -1) break;
        guys.push_back(me);
      }
      me = i;
      for (int jt = 0; jt < 2; jt++) {
        me = nxt(me);
        if (me == -1) break;
        guys.push_back(me);
      }
      rf[i] = i + 1;
      lf[i] = i - 1;
      for (int i : guys) relax(i);
      cnt[s[i]]--;
    };
    while (cnt[0] != cnt[1] || cnt[0] != cnt[2]) {
      /*
      string str=  "";
      for (int x : q) str += (s[x] + 'A');
      cout << str << endl;
      */
      int x = 0;
      int y= -1;
      int mn = 0;
      for (int i = 0; i < 3; i++) {
        if (cnt[i] < cnt[mn]) {
          mn = i;
        }
        if (cnt[i] > cnt[x]) {
          x = i;
          y = -1;
        } else if (cnt[i] == cnt[x]) {
          y = i;
        }
      }
      bool good = false;
      auto clear_two = [&] (int i, int j) {
       while (!ok[i][j].empty()) {
          int ind = ok[i][j].back();
          if (!good_two(ind) || s[nxt(ind)] != j) {
            ok[i][j].pop_back();
          } else {
            break;
          }
        }
        if (ok[i][j].empty()) return false;
        int ind = ok[i][j].back();
        int jt = nxt(ind);
        del(ind);
        del(jt);
        return true;
      };
      auto clear_one = [&] (int i) {
       while (!ok[i][i].empty()) {
          int ind = ok[i][i].back();
          if (!good_one(ind)) {
            ok[i][i].pop_back();
          } else {
            break;
          }
        }
        if (ok[i][i].empty()) return false;
        int ind = ok[i][i].back();
        del(ind);
        return true;
      };
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          if (i == x && j == y && i != j && clear_two(i, j)) {
            good = true;
            i = 3;
            break;
          }
        }
      }
      if (good) continue;
      for (int i = 0; i < 3; i++) {
        if (i == x || i == y) {
          if (clear_one(i)) {
            good = true;
            break;
          }
        }
      }
      if (good) continue;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          if (i != mn && j != mn && i != j && clear_two(i, j)) {
            good = true;
            i = 3;
            break;
          }
        }
      }
      if (good) continue;
      for (int i = 0; i < 3; i++) {
        if (i != mn) {
          if (clear_one(i)) {
            good = true;
            break;
          }
        }
      }
      assert(good);
    }
    string str = "";
    for (int i = 0; i < n; i++) {
      if (lf[i] == i)
        str += s[i] + 'A';
    }
    return str;
  };
  string s;
  cin >> s;
  cout << fast(longest(s)) << endl;
  return 0;
  auto naive = [&] (string s) {
    int n = (int) s.size();
    int lim = (1 << n);
    map <char, int> best;
    int mx = 0;
    for (int mask = 0; mask < lim; mask++) {
      string str = "";
      for (int i = 0; i < n; i++) {
        if ((mask >> i) & 1) {
          str += s[i];
        }
      }
      bool bad = false;
      map <char, int> cnt;
      for (int i = 1; i < (int) str.size(); i++) {
        if (str[i] == str[i - 1]) {
          bad = true;
        }
      }
      for (auto c : str) {
        cnt[c]++;
      }
      for (auto c : cnt) {
        best[c.first] = max(best[c.first], c.second);
      }
      if (!bad && cnt['A'] == cnt['B'] && cnt['A'] == cnt['C']) {
        mx = max(mx, (int) str.size());
      }
    }
    return mx;
  };
  for (int tc = 1; ; tc++) {
    int n = rnd() % 15 + 1;
    string str = "";
    for (int i = 0; i < n; i++) {
      str += ('A' + rnd() % 3);
      while (i && str[i] == str[i - 1])
        str[i] = 'A' + rnd() % 3;
    }
    int need = fast(longest(str)).size();
    if (naive(str) != need) {
      cout << longest(str) << endl;
      cout << str << ' ' << naive(longest(str)) << endl;
      cout << naive(str) << ' ' << need << endl;
      return 0;
    }
    if (tc % 1000 == 0) {
      cout << tc << endl;
    }
  }
}


Measured memory_bytes: 48856