import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	s=RD()[::-1]+"DDDDD"

	i=0
	cnt=0
	ans=0

	#print(s)

	while i<=len(s)-3:
		if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	print(ans)





if __name__ == "__main__":
	main() import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def RD(): return input().rstrip().decode() RD def II(): return int(input()) II def FI(): return int(input()) FI def MI(): return map(int,input().split()) MI def MF(): return map(float,input().split()) MF def LI(): return list(map(int,input().split())) LI def LF(): return list(map(float,input().split())) LF def TI(): return tuple(map(int,input().split()))
# rstrip().decode() TI def main():
	s=RD()[::-1]+"DDDDD"

	i=0
	cnt=0
	ans=0

	#print(s)

	while i<=len(s)-3:
		if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	print(ans) main s=RD()[::-1]+"DDDDD" s RD()[::-1]+"DDDDD" RD()[::-1] () RD ::-1 -1 "DDDDD" i=0 i 0 cnt=0 cnt 0 ans=0 ans 0 while i<=len(s)-3:
		if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	 i<=len(s)-3 i len(s)-3 len(s) len s 3 if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	 s[i:i+2]=="CB" s[i:i+2] s i:i+2 i i+2 i 2 "CB" cnt+=1 cnt 1 i+=2 i 2 elif s[i]=="A":
			ans+=cnt
			i+=1
		 s[i]=="A" s[i] s i "A" ans+=cnt ans cnt i+=1 i 1 cnt=0 cnt 0 i+=1 i 1 print(ans) print ans if __name__ == "__main__":
	main() __name__ == "__main__" __name__ "__main__" main() main def FI(): return int(input()) def FI(): return int(input()) FI input = sys.stdin.buffer.readline sys.stdin.buffer.readline input def MI(): return map(int,input().split()) def MI(): return map(int,input().split()) MI def LI(): return list(map(int,input().split())) def LI(): return list(map(int,input().split())) LI def main():
	s=RD()[::-1]+"DDDDD"

	i=0
	cnt=0
	ans=0

	#print(s)

	while i<=len(s)-3:
		if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	print(ans) def main():
	s=RD()[::-1]+"DDDDD"

	i=0
	cnt=0
	ans=0

	#print(s)

	while i<=len(s)-3:
		if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	print(ans) main def TI(): return tuple(map(int,input().split()))
# rstrip().decode() def TI(): return tuple(map(int,input().split()))
# rstrip().decode() TI def RD(): return input().rstrip().decode() def RD(): return input().rstrip().decode() RD def LF(): return list(map(float,input().split())) def LF(): return list(map(float,input().split())) LF def II(): return int(input()) def II(): return int(input()) II def MF(): return map(float,input().split()) def MF(): return map(float,input().split()) MF
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	s=RD()[::-1]+"DDDDD"

	i=0
	cnt=0
	ans=0

	#print(s)

	while i<=len(s)-3:
		if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	print(ans)





if __name__ == "__main__":
	main()
