import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    ans = 0
    s = input().strip()
    # print(s)
    pre = ""
    state = ""
    cnta = 0
    for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

    print(ans)

if __name__ == '__main__':
    main()

"""
9999
3

2916
""" import sys sys def getN():
    return int(input()) getN return int(input()) int(input()) int input() input def getNM():
    return map(int, input().split()) getNM return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split def getlist():
    return list(map(int, input().split())) getlist return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split import math math import heapq heapq from collections import defaultdict, Counter, deque MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 INF = 10**15 INF 10**15 10 15 def main():
    ans = 0
    s = input().strip()
    # print(s)
    pre = ""
    state = ""
    cnta = 0
    for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

    print(ans) main ans = 0 ans 0 s = input().strip() s input().strip() ().strip () input strip pre = "" pre "" state = "" state "" cnta = 0 cnta 0 for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

     c s if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
         c == "A" c "A" if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
         state == "A" state "A" cnta += 1 cnta 1 state = "A" state "A" cnta = 1 cnta 1 if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
         c == "B" c "B" if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
         state == "A" state "A" state = "AB" state "AB" state = "" state "" cnta = 0 cnta 0 if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

     c == "C" c "C" if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

     state == "AB" state "AB" ans += cnta ans cnta state = "A" state "A" state = "" state "" cnta = 0 cnta 0 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main """
9999
3

2916
""" def getN():
    return int(input()) def getN():
    return int(input()) getN def main():
    ans = 0
    s = input().strip()
    # print(s)
    pre = ""
    state = ""
    cnta = 0
    for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

    print(ans) def main():
    ans = 0
    s = input().strip()
    # print(s)
    pre = ""
    state = ""
    cnta = 0
    for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

    print(ans) main MOD = 10**9 + 7 10**9 + 7 MOD INF = 10**15 10**15 INF def getlist():
    return list(map(int, input().split())) def getlist():
    return list(map(int, input().split())) getlist def getNM():
    return map(int, input().split()) def getNM():
    return map(int, input().split()) getNM
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15


def main():
    ans = 0
    s = input().strip()
    # print(s)
    pre = ""
    state = ""
    cnta = 0
    for c in s:
        if c == "A":
            if state == "A":
                cnta += 1
            else:
                state = "A"
                cnta = 1
        if c == "B":
            if state == "A":
                state = "AB"
            else:
                state = ""
                cnta = 0
        if c == "C":
            if state == "AB":
                ans += cnta
                state = "A"
            else:
                state = ""
                cnta = 0

    print(ans)

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""