/**
 *    author:  tourist
 *    created: 29.11.2019 00:35:14       
**/
#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  {
    string ns = "";
    for (char c : s) {
      if (ns.empty() || c != ns.back()) {
        ns += c;
      }
    }
    s = ns;
  }
  vector<string> words(1, "");
  for (char c : s) {
    if (c == 'A') {
      words.emplace_back();
    } else {
      words.back() += c;
    }
  }
  int sz = (int) words.size();
  vector<int> pr(sz);
  vector<int> ne(sz);
  for (int i = 0; i < sz; i++) {
    pr[i] = i - 1;
    ne[i] = i + 1;
  }
  int head = 0;
  int tail = sz - 1;
  vector<bool> alive(sz, true);
  vector<int> gp;
  vector<int> longs;
  auto Remove = [&](int x) {
    if (head == x) {
      head = ne[x];
    }
    if (tail == x) {
      tail = pr[x];
    }
    alive[x] = false;
    if (ne[x] < sz) {
      pr[ne[x]] = pr[x];
    }
    if (pr[x] >= 0) {
      ne[pr[x]] = ne[x];
    }
    if (pr[x] >= 0 && ne[x] < sz && !words[pr[x]].empty() && !words[ne[x]].empty() && words[pr[x]].back() != words[ne[x]][0]) {
      gp.push_back(pr[x]);
    }
  };
  int nA = (int) words.size() - 1;
  int nB = (int) count(s.begin(), s.end(), 'B');
  int nC = (int) count(s.begin(), s.end(), 'C');
  vector<vector<int>> ones(2);
  auto MaybeOne = [&](int i) {
    if (words[i].size() == 1) {
      ones[(int) (words[i][0] - 'B')].push_back(i);
    }
  };
  vector<vector<int>> at_back(2);
  vector<vector<int>> at_front(2);
  auto CheckChars = [&](int i) {
    if (!words[i].empty()) {
      at_back[(int) (words[i].back() - 'B')].push_back(i);
      at_front[(int) (words[i][0] - 'B')].push_back(i);
    }
  };
  for (int i = 0; i < sz; i++) {
    MaybeOne(i);
    CheckChars(i);
  }
  for (int i = 0; i < sz - 1; i++) {
    if (!words[i].empty() && !words[i + 1].empty() && words[i].back() != words[i + 1][0]) {
      gp.push_back(i);
    }
  }
  for (int i = 0; i < sz; i++) {
    if (words[i].size() >= 3) {
      longs.push_back(i);
    }
  }
  while (nA != nB || nA != nC || nB != nC) {
    if (nA >= nB && nA >= nC) {
      if (nA == max(nB, nC)) {
        char who = (nB > nC ? 'B' : 'C');
        auto& v = ones[(int) (who - 'B')];
        while (!v.empty() && (!alive[v.back()] || words[v.back()].size() != 1)) {
          v.pop_back();
        }
        if (!v.empty()) {
          int i = v.back();
          v.pop_back();
          Remove(i);
          --nA;
          if (who == 'B') --nB; else --nC;
          continue;
        }
      }
      if (words[head] == "") {
        Remove(head);
        --nA;
        continue;
      }
      if (words[tail] == "") {
        Remove(tail);
        --nA;
        continue;
      }
      bool found = false;
      while (!gp.empty()) {
        int i = gp.back();
        if (alive[i] && ne[i] < sz && words[i].back() != words[ne[i]][0]) {
          words[i] += words[ne[i]];
          if (words[i].size() >= 3) {
            longs.push_back(i);
          }
          Remove(ne[i]);
          CheckChars(i);
          found = true;
          --nA;
          break;
        }
        gp.pop_back();
      }
      if (found) {
        continue;
      }
      char who = (nB > nC ? 'B' : 'C');
      auto& v = at_back[(int) (who - 'B')];
      while (!v.empty()) {
        int i = v.back();
        if (alive[i] && !words[i].empty() && ne[i] < sz && words[i].back() == who) {
          words[i].pop_back();
          words[i] += words[ne[i]];
          if (words[i].size() >= 3) {
            longs.push_back(i);
          }
          Remove(ne[i]);
          MaybeOne(i);
          CheckChars(i);
          found = true;
          --nA;
          if (who == 'B') --nB; else --nC;
          break;
        }
        v.pop_back();
      }
      assert(found);
      continue;
    }
    if (nB == nC) {
      bool found = false;
      while (!longs.empty()) {
        int i = longs.back();
        if (alive[i] && words[i].size() >= 3) {
          words[i].pop_back();
          words[i].pop_back();
          --nB;
          --nC;
          MaybeOne(i);
          found = true;
          break;
        }
        longs.pop_back();
      }
      if (found) {
        continue;
      }
    }
    char me = (nB > nC ? 'B' : 'C');
    if (!words[head].empty() && words[head][0] == me) {
      words[head].erase(words[head].begin());
      if (me == 'B') --nB; else --nC;
      MaybeOne(head);
      CheckChars(head);
      continue;
    }
    if (!words[tail].empty() && words[tail].back() == me) {
      words[tail].pop_back();
      if (me == 'B') --nB; else --nC;
      MaybeOne(tail);
      CheckChars(tail);
      continue;
    }
    bool found = false;
    {
      auto& v = at_back[(int) (me - 'B')];
      while (!v.empty()) {
        int i = v.back();
        if (alive[i] && words[i].size() > 1 && words[i].back() == me) {
          words[i].pop_back();
          if (me == 'B') --nB; else --nC;
          MaybeOne(i);
          CheckChars(i);
          found = true;
          break;
        }
        v.pop_back();
      }
    }
    if (!found) {
      auto& v = at_front[(int) (me - 'B')];
      while (!v.empty()) {
        int i = v.back();
        if (alive[i] && words[i].size() > 1 && words[i][0] == me) {
          words[i].erase(words[i].begin());
          if (me == 'B') --nB; else --nC;
          MaybeOne(i);
          CheckChars(i);
          found = true;
          break;
        }
        v.pop_back();
      }
    }
    if (found) {
      continue;
    }
    auto& v = ones[(int) (me - 'B')];
    while (!v.empty() && (!alive[v.back()] || words[v.back()].size() != 1)) {
      v.pop_back();
    }
    assert(!v.empty());
    int i = v.back();
    v.pop_back();
    Remove(i);
    if (me == 'B') --nB; else --nC;
    --nA;
  }
  for (int i = head; i < sz; i = ne[i]) {
    if (i > head) {
      cout << 'A';
    }
    cout << words[i];
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 558916