s = input()
s = s.replace("BC", "D")
acnt = 0
mode = 1
ans = 0
"""
AD -> DA
AAD -> ADA -> DAA
ADAD -> DAAD -> DADA -> DDAA

Dを見る→前にあるAは何個？（その分だけ数える）
"""
for i in range(len(s)):
	if s[i] == "A":
		acnt += 1
	elif s[i] == "D":
		ans += acnt
	else:
		acnt = 0
print(ans) s = input() s input() input s = s.replace("BC", "D") s s.replace("BC", "D") s.replace s replace "BC" "D" acnt = 0 acnt 0 mode = 1 mode 1 ans = 0 ans 0 """
AD -> DA
AAD -> ADA -> DAA
ADAD -> DAAD -> DADA -> DDAA

Dを見る→前にあるAは何個？（その分だけ数える）
""" for i in range(len(s)):
	if s[i] == "A":
		acnt += 1
	elif s[i] == "D":
		ans += acnt
	else:
		acnt = 0 i range(len(s)) range len(s) len s if s[i] == "A":
		acnt += 1
	elif s[i] == "D":
		ans += acnt
	else:
		acnt = 0 s[i] == "A" s[i] s i "A" acnt += 1 acnt 1 elif s[i] == "D":
		ans += acnt
	 s[i] == "D" s[i] s i "D" ans += acnt ans acnt acnt = 0 acnt 0 print(ans) print ans acnt = 0 0 acnt ans += acnt acnt ans acnt = 0 0 acnt acnt += 1 1 acnt mode = 1 1 mode s = input() input() s ans = 0 0 ans s = s.replace("BC", "D") s.replace("BC", "D") s
s = input()
s = s.replace("BC", "D")
acnt = 0
mode = 1
ans = 0
"""
AD -> DA
AAD -> ADA -> DAA
ADAD -> DAAD -> DADA -> DDAA

Dを見る→前にあるAは何個？（その分だけ数える）
"""
for i in range(len(s)):
	if s[i] == "A":
		acnt += 1
	elif s[i] == "D":
		ans += acnt
	else:
		acnt = 0
print(ans)