import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    S = S.replace("BC", "X")
    S = S.replace("C", "B")
    S = S.split("B")
    answer = 0
    for s in S:
        place = []
        c = 0
        n = len(s)
        for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
        for p in place:
            c -= 1
            answer += n - c - p
    print(answer)


if __name__ == "__main__":
    main() import sys sys def input():
    return sys.stdin.readline().strip() input return sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 def main():
    S = input()
    S = S.replace("BC", "X")
    S = S.replace("C", "B")
    S = S.split("B")
    answer = 0
    for s in S:
        place = []
        c = 0
        n = len(s)
        for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
        for p in place:
            c -= 1
            answer += n - c - p
    print(answer) main S = input() S input() input S = S.replace("BC", "X") S S.replace("BC", "X") S.replace S replace "BC" "X" S = S.replace("C", "B") S S.replace("C", "B") S.replace S replace "C" "B" S = S.split("B") S S.split("B") S.split S split "B" answer = 0 answer 0 for s in S:
        place = []
        c = 0
        n = len(s)
        for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
        for p in place:
            c -= 1
            answer += n - c - p
     s S place = [] place [] c = 0 c 0 n = len(s) n len(s) len s for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
         i range(n) range n if s[i] == "A":
                c += 1
                place.append(i + 1)
         s[i] == "A" s[i] s i "A" c += 1 c 1 place.append(i + 1) place.append place append i + 1 i 1 for p in place:
            c -= 1
            answer += n - c - p
     p place c -= 1 c 1 answer += n - c - p answer n - c - p n - c n c p print(answer) print answer if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def input():
    return sys.stdin.readline().strip() def input():
    return sys.stdin.readline().strip() input def main():
    S = input()
    S = S.replace("BC", "X")
    S = S.replace("C", "B")
    S = S.split("B")
    answer = 0
    for s in S:
        place = []
        c = 0
        n = len(s)
        for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
        for p in place:
            c -= 1
            answer += n - c - p
    print(answer) def main():
    S = input()
    S = S.replace("BC", "X")
    S = S.replace("C", "B")
    S = S.split("B")
    answer = 0
    for s in S:
        place = []
        c = 0
        n = len(s)
        for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
        for p in place:
            c -= 1
            answer += n - c - p
    print(answer) main
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    S = S.replace("BC", "X")
    S = S.replace("C", "B")
    S = S.split("B")
    answer = 0
    for s in S:
        place = []
        c = 0
        n = len(s)
        for i in range(n):
            if s[i] == "A":
                c += 1
                place.append(i + 1)
        for p in place:
            c -= 1
            answer += n - c - p
    print(answer)


if __name__ == "__main__":
    main()
