import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    ans = 0
    A_count = 0
    i = 0
    N = len(S)
    while i < N - 1:
        if S[i] == "A":
            A_count += 1
            i += 1
        elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
        else:
            A_count = 0
            i += 1

    print(ans)


if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    S = input().rstrip()

    ans = 0
    A_count = 0
    i = 0
    N = len(S)
    while i < N - 1:
        if S[i] == "A":
            A_count += 1
            i += 1
        elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
        else:
            A_count = 0
            i += 1

    print(ans) main S = input().rstrip() S input().rstrip() ().rstrip () input rstrip ans = 0 ans 0 A_count = 0 A_count 0 i = 0 i 0 N = len(S) N len(S) len S while i < N - 1:
        if S[i] == "A":
            A_count += 1
            i += 1
        elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
        else:
            A_count = 0
            i += 1

     i < N - 1 i N - 1 N 1 if S[i] == "A":
            A_count += 1
            i += 1
        elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
        else:
            A_count = 0
            i += 1

     S[i] == "A" S[i] S i "A" A_count += 1 A_count 1 i += 1 i 1 elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
         S[i:i + 2] == "BC" S[i:i + 2] S i:i + 2 i i + 2 i 2 "BC" ans += A_count ans A_count i += 2 i 2 A_count = 0 A_count 0 i += 1 i 1 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    S = input().rstrip()

    ans = 0
    A_count = 0
    i = 0
    N = len(S)
    while i < N - 1:
        if S[i] == "A":
            A_count += 1
            i += 1
        elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
        else:
            A_count = 0
            i += 1

    print(ans) def main():
    S = input().rstrip()

    ans = 0
    A_count = 0
    i = 0
    N = len(S)
    while i < N - 1:
        if S[i] == "A":
            A_count += 1
            i += 1
        elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
        else:
            A_count = 0
            i += 1

    print(ans) main input = sys.stdin.readline sys.stdin.readline input
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    ans = 0
    A_count = 0
    i = 0
    N = len(S)
    while i < N - 1:
        if S[i] == "A":
            A_count += 1
            i += 1
        elif S[i:i + 2] == "BC":
            ans += A_count
            i += 2
        else:
            A_count = 0
            i += 1

    print(ans)


if __name__ == "__main__":
    main()
