import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#n = int(input())
	#b , c = tin()
	#s = input()
	s=input()
	pre='C'
	ret = 0
	a_num=0
	for c in s:
		d = pre + c
		if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		pre = c
	return ret
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret) import sys sys input_methods=['clipboard','file','key'] input_methods ['clipboard','file','key'] 'clipboard' 'file' 'key' using_method=0 using_method 0 input_method=input_methods[using_method] input_method input_methods[using_method] input_methods using_method tin=lambda : map(int, input().split()) tin lambda : map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split lin=lambda : list(tin()) lin lambda : list(tin()) list(tin()) list tin() tin mod=1000000007 mod 1000000007 def main():
	#n = int(input())
	#b , c = tin()
	#s = input()
	s=input()
	pre='C'
	ret = 0
	a_num=0
	for c in s:
		d = pre + c
		if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		pre = c
	return ret
	
	
#+++++ main s=input() s input() input pre='C' pre 'C' ret = 0 ret 0 a_num=0 a_num 0 for c in s:
		d = pre + c
		if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		pre = c
	 c s d = pre + c d pre + c pre c if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		 d == 'AA' d 'AA' a_num += 1 a_num 1 elif d == 'BA':
			a_num=1
		 d == 'BA' d 'BA' a_num=1 a_num 1 elif d == 'CA':
			a_num += 1
		 d == 'CA' d 'CA' a_num += 1 a_num 1 elif d == 'AB':
			pass
		 d == 'AB' d 'AB' elif d== 'BB':
			a_num = 0
		 d== 'BB' d 'BB' a_num = 0 a_num 0 elif d == 'CB':
			pass
		 d == 'CB' d 'CB' elif d == 'AC':
			a_num = 0
		 d == 'AC' d 'AC' a_num = 0 a_num 0 elif d == 'BC':
			ret += a_num
		 d == 'BC' d 'BC' ret += a_num ret a_num a_num = 0 a_num 0 pre = c pre c return ret ret isTest=False isTest False def pa(v):
	if isTest:
		print(v)
		 pa if isTest:
		print(v)
		 isTest print(v) print v v v def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l input_clipboard import clipboard clipboard input_text=clipboard.get() input_text clipboard.get() clipboard.get clipboard get input_l=input_text.splitlines() input_l input_text.splitlines() input_text.splitlines input_text splitlines for l in input_l:
		yield l l input_l yield l l if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret) __name__ == "__main__" __name__ "__main__" if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	 sys.platform =='ios' sys.platform sys platform 'ios' if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		 input_method==input_methods[0] input_method input_methods[0] input_methods 0 ic=input_clipboard() ic input_clipboard() input_clipboard input = lambda : ic.__next__() input lambda : ic.__next__() ic.__next__() ic.__next__ ic __next__ elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		 input_method==input_methods[1] input_method input_methods[1] input_methods 1 sys.stdin=open('inputFile.txt') sys.stdin sys stdin open('inputFile.txt') open 'inputFile.txt' isTest=True isTest True ret = main() ret main() main if ret is not None:
		print(ret) ret is not None ret None print(ret) print ret mod=1000000007 1000000007 mod def pa(v):
	if isTest:
		print(v)
		 def pa(v):
	if isTest:
		print(v)
		 pa tin=lambda : map(int, input().split()) lambda : map(int, input().split()) tin ret = main() main() ret input_methods=['clipboard','file','key'] ['clipboard','file','key'] input_methods isTest=True True isTest def main():
	#n = int(input())
	#b , c = tin()
	#s = input()
	s=input()
	pre='C'
	ret = 0
	a_num=0
	for c in s:
		d = pre + c
		if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		pre = c
	return ret
	
	
#+++++ def main():
	#n = int(input())
	#b , c = tin()
	#s = input()
	s=input()
	pre='C'
	ret = 0
	a_num=0
	for c in s:
		d = pre + c
		if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		pre = c
	return ret
	
	
#+++++ main def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l input_clipboard using_method=0 0 using_method isTest=False False isTest ic=input_clipboard() input_clipboard() ic lin=lambda : list(tin()) lambda : list(tin()) lin input = lambda : ic.__next__() lambda : ic.__next__() input input_method=input_methods[using_method] input_methods[using_method] input_method
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#n = int(input())
	#b , c = tin()
	#s = input()
	s=input()
	pre='C'
	ret = 0
	a_num=0
	for c in s:
		d = pre + c
		if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		pre = c
	return ret
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)