from collections import deque
import heapq

s = input()
s += " "

S = ""

for i in range(len(s)-1):
    if s[i] == "B" and s[i+1] == "C":
        S += "Z"

    elif i > 0 and s[i] == "C" and s[i-1] == "B":
        continue
    else:
        S += s[i]

#print (S)
la = deque([])
ans = 0
for i in range(len(S)):

    if S[i] == "A":
        la.append(i)

    elif S[i] == "Z" and len(la) > 0:
        lastA = la.popleft()
        ans += i - lastA
        la.append(i)

    else:
        la = deque([])

print (ans) from collections import deque import heapq heapq s = input() s input() input s += " " s " " S = "" S "" for i in range(len(s)-1):
    if s[i] == "B" and s[i+1] == "C":
        S += "Z"

    elif i > 0 and s[i] == "C" and s[i-1] == "B":
        continue
    else:
        S += s[i]

#print (S) i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i] == "B" and s[i+1] == "C":
        S += "Z"

    elif i > 0 and s[i] == "C" and s[i-1] == "B":
        continue
    else:
        S += s[i]

#print (S) s[i] == "B" and s[i+1] == "C" s[i] == "B" s[i] s i "B" s[i+1] == "C" s[i+1] s i+1 i 1 "C" S += "Z" S "Z" elif i > 0 and s[i] == "C" and s[i-1] == "B":
        continue
     i > 0 and s[i] == "C" and s[i-1] == "B" i > 0 and s[i] == "C" i > 0 i 0 s[i] == "C" s[i] s i "C" s[i-1] == "B" s[i-1] s i-1 i 1 "B" continue S += s[i] S s[i] s i la = deque([]) la deque([]) deque [] ans = 0 ans 0 for i in range(len(S)):

    if S[i] == "A":
        la.append(i)

    elif S[i] == "Z" and len(la) > 0:
        lastA = la.popleft()
        ans += i - lastA
        la.append(i)

    else:
        la = deque([]) i range(len(S)) range len(S) len S if S[i] == "A":
        la.append(i)

    elif S[i] == "Z" and len(la) > 0:
        lastA = la.popleft()
        ans += i - lastA
        la.append(i)

    else:
        la = deque([]) S[i] == "A" S[i] S i "A" la.append(i) la.append la append i elif S[i] == "Z" and len(la) > 0:
        lastA = la.popleft()
        ans += i - lastA
        la.append(i)

     S[i] == "Z" and len(la) > 0 S[i] == "Z" S[i] S i "Z" len(la) > 0 len(la) len la 0 lastA = la.popleft() lastA la.popleft() la.popleft la popleft ans += i - lastA ans i - lastA i lastA la.append(i) la.append la append i la = deque([]) la deque([]) deque [] print (ans) print ans S += "Z" "Z" S lastA = la.popleft() la.popleft() lastA S += s[i] s[i] S S = "" "" S la = deque([]) deque([]) la la = deque([]) deque([]) la ans = 0 0 ans s = input() input() s s += " " " " s ans += i - lastA i - lastA ans
from collections import deque
import heapq

s = input()
s += " "

S = ""

for i in range(len(s)-1):
    if s[i] == "B" and s[i+1] == "C":
        S += "Z"

    elif i > 0 and s[i] == "C" and s[i-1] == "B":
        continue
    else:
        S += s[i]

#print (S)
la = deque([])
ans = 0
for i in range(len(S)):

    if S[i] == "A":
        la.append(i)

    elif S[i] == "Z" and len(la) > 0:
        lastA = la.popleft()
        ans += i - lastA
        la.append(i)

    else:
        la = deque([])

print (ans)
