import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	S = [s for s in S]

	# AABCBC = 4 (BCが2つ、その前にAが2つ) 2*2 = 4
	# ABCABC = 3 (1つのBCには前にAが1つ、もう1つは前にAが2つ) 2*1+1*1 = 3
	# => それぞれのBCの前にAがある数で回数が決まる！
	# f(x) = BCの前にあるAの数 * BCの数

	ans = 0
	sts = 0
	acnt = 0
	i = 0
	while i <= len(S)-2:
		if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	print(ans)

if __name__ == '__main__':
	main()	 import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt') sys.platform in (['ios','darwin','win32']) sys.platform sys platform ['ios','darwin','win32'] 'ios' 'darwin' 'win32' sys.stdin=open('Untitled.txt') sys.stdin sys stdin open('Untitled.txt') open 'Untitled.txt' input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def INT(): return int(input()) INT int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s def MAP(): return [int(s) for s in input().split()] MAP def main():
	S = input().rstrip()
	S = [s for s in S]

	# AABCBC = 4 (BCが2つ、その前にAが2つ) 2*2 = 4
	# ABCABC = 3 (1つのBCには前にAが1つ、もう1つは前にAが2つ) 2*1+1*1 = 3
	# => それぞれのBCの前にAがある数で回数が決まる！
	# f(x) = BCの前にあるAの数 * BCの数

	ans = 0
	sts = 0
	acnt = 0
	i = 0
	while i <= len(S)-2:
		if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	print(ans) main S = input().rstrip() S input().rstrip() ().rstrip () input rstrip s for s in S for s in S s S for s in S s S = [s for s in S] S [s for s in S] ans = 0 ans 0 sts = 0 sts 0 acnt = 0 acnt 0 i = 0 i 0 while i <= len(S)-2:
		if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	 i <= len(S)-2 i len(S)-2 len(S) len S 2 if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	 sts == 0 and S[i] == 'A' sts == 0 sts 0 S[i] == 'A' S[i] S i 'A' sts = 1 sts 1 acnt += 1 acnt 1 i += 1 i 1 elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		 sts == 1 and S[i] == 'A' sts == 1 sts 1 S[i] == 'A' S[i] S i 'A' acnt += 1 acnt 1 i += 1 i 1 elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		 sts == 1 and S[i]=='B' and S[i+1]=='C' sts == 1 and S[i]=='B' sts == 1 sts 1 S[i]=='B' S[i] S i 'B' S[i+1]=='C' S[i+1] S i+1 i 1 'C' ans += acnt ans acnt i += 2 i 2 sts = 0 sts 0 acnt = 0 acnt 0 i += 1 i 1 print(ans) print ans if __name__ == '__main__':
	main()	 __name__ == '__main__' __name__ '__main__' main() main def INT(): return int(input()) def INT(): return int(input()) INT def main():
	S = input().rstrip()
	S = [s for s in S]

	# AABCBC = 4 (BCが2つ、その前にAが2つ) 2*2 = 4
	# ABCABC = 3 (1つのBCには前にAが1つ、もう1つは前にAが2つ) 2*1+1*1 = 3
	# => それぞれのBCの前にAがある数で回数が決まる！
	# f(x) = BCの前にあるAの数 * BCの数

	ans = 0
	sts = 0
	acnt = 0
	i = 0
	while i <= len(S)-2:
		if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	print(ans) def main():
	S = input().rstrip()
	S = [s for s in S]

	# AABCBC = 4 (BCが2つ、その前にAが2つ) 2*2 = 4
	# ABCABC = 3 (1つのBCには前にAが1つ、もう1つは前にAが2つ) 2*1+1*1 = 3
	# => それぞれのBCの前にAがある数で回数が決まる！
	# f(x) = BCの前にあるAの数 * BCの数

	ans = 0
	sts = 0
	acnt = 0
	i = 0
	while i <= len(S)-2:
		if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	print(ans) main input = sys.stdin.readline sys.stdin.readline input def MAP(): return [int(s) for s in input().split()] def MAP(): return [int(s) for s in input().split()] MAP
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()
	S = [s for s in S]

	# AABCBC = 4 (BCが2つ、その前にAが2つ) 2*2 = 4
	# ABCABC = 3 (1つのBCには前にAが1つ、もう1つは前にAが2つ) 2*1+1*1 = 3
	# => それぞれのBCの前にAがある数で回数が決まる！
	# f(x) = BCの前にあるAの数 * BCの数

	ans = 0
	sts = 0
	acnt = 0
	i = 0
	while i <= len(S)-2:
		if sts == 0 and S[i] == 'A':
			sts = 1
			acnt += 1
			i += 1
		elif sts == 1 and S[i] == 'A':
			acnt += 1
			i += 1
		elif sts == 1 and S[i]=='B' and S[i+1]=='C':
			ans += acnt
			i += 2
		else:
			sts = 0
			acnt = 0
			i += 1
	
	print(ans)

if __name__ == '__main__':
	main()	