var main = standardInput => {
  var s = standardInput;
  var count = 0;

  function exist(str) {
    return s.indexOf(str) !== -1;
  }

  while (exist("ABCABC")) {
    var i = s.indexOf("ABCABC");
    var before = s.substr(0, i);
    var after = s.substr(i + 6) || "";
    s = before + "BCBCAA" + after;
    count += 3;
    s = s.substr(s.indexOf("A"))
  }

  while (exist("ABCBC")) {
    var i = s.indexOf("ABCBC");
    var before = s.substr(0, i);
    var after = s.substr(i + 5) || "";
    s = before + "BCBCA" + after;
    count += 2;
    s = s.substr(s.indexOf("A"))
  }

  while (exist("AABC")) {
    var i = s.indexOf("AABC");
    var before = s.substr(0, i);
    var after = s.substr(i + 4) || "";
    s = before + "BCAA" + after;
    count += 2;
    s = s.substr(s.indexOf("A"))
  }

  while (exist("ABC")) {
    var i = s.indexOf("ABC");
    var after = s.substr(i + 3) || "";
    s = "BCA" + after;
    count += 1;
    s = s.substr(s.indexOf("A"))
  }
  console.log(count);
};

main(require("fs").readFileSync("/dev/stdin", "UTF-8"));
