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