S = str(input())

count =  0
AP_streak = 0
P_pos = []
P_count = 0

S=S.replace('BC', 'P')

N = len(S)

for i in range (0, N):
	V = S[i]
	if V != 'P' and V!= 'A':
		count+=sum(P_pos)-(P_count*(P_count+1))//2
		AP_streak = 0
		P_pos = []
		P_count = 0
	if V == 'A':
		AP_streak+=1
	if V == 'P':
		if AP_streak > 0:
			AP_streak+=1
			P_count+=1
			P_pos.append(AP_streak)

count+=sum(P_pos)-(P_count*(P_count+1))//2

print(count) S = str(input()) S str(input()) str input() input count =  0 count 0 AP_streak = 0 AP_streak 0 P_pos = [] P_pos [] P_count = 0 P_count 0 S=S.replace('BC', 'P') S S.replace('BC', 'P') S.replace S replace 'BC' 'P' N = len(S) N len(S) len S for i in range (0, N):
	V = S[i]
	if V != 'P' and V!= 'A':
		count+=sum(P_pos)-(P_count*(P_count+1))//2
		AP_streak = 0
		P_pos = []
		P_count = 0
	if V == 'A':
		AP_streak+=1
	if V == 'P':
		if AP_streak > 0:
			AP_streak+=1
			P_count+=1
			P_pos.append(AP_streak) i range (0, N) range 0 N V = S[i] V S[i] S i if V != 'P' and V!= 'A':
		count+=sum(P_pos)-(P_count*(P_count+1))//2
		AP_streak = 0
		P_pos = []
		P_count = 0
	 V != 'P' and V!= 'A' V != 'P' V 'P' V!= 'A' V 'A' count+=sum(P_pos)-(P_count*(P_count+1))//2 count sum(P_pos)-(P_count*(P_count+1))//2 sum(P_pos) sum P_pos (P_count*(P_count+1))//2 P_count*(P_count+1) P_count P_count+1 P_count 1 2 AP_streak = 0 AP_streak 0 P_pos = [] P_pos [] P_count = 0 P_count 0 if V == 'A':
		AP_streak+=1
	 V == 'A' V 'A' AP_streak+=1 AP_streak 1 if V == 'P':
		if AP_streak > 0:
			AP_streak+=1
			P_count+=1
			P_pos.append(AP_streak) V == 'P' V 'P' if AP_streak > 0:
			AP_streak+=1
			P_count+=1
			P_pos.append(AP_streak) AP_streak > 0 AP_streak 0 AP_streak+=1 AP_streak 1 P_count+=1 P_count 1 P_pos.append(AP_streak) P_pos.append P_pos append AP_streak count+=sum(P_pos)-(P_count*(P_count+1))//2 count sum(P_pos)-(P_count*(P_count+1))//2 sum(P_pos) sum P_pos (P_count*(P_count+1))//2 P_count*(P_count+1) P_count P_count+1 P_count 1 2 print(count) print count P_count = 0 0 P_count V = S[i] S[i] V AP_streak+=1 1 AP_streak P_count+=1 1 P_count AP_streak = 0 0 AP_streak N = len(S) len(S) N P_pos = [] [] P_pos AP_streak+=1 1 AP_streak P_pos = [] [] P_pos count =  0 0 count AP_streak = 0 0 AP_streak S=S.replace('BC', 'P') S.replace('BC', 'P') S count+=sum(P_pos)-(P_count*(P_count+1))//2 sum(P_pos)-(P_count*(P_count+1))//2 count P_count = 0 0 P_count S = str(input()) str(input()) S count+=sum(P_pos)-(P_count*(P_count+1))//2 sum(P_pos)-(P_count*(P_count+1))//2 count
S = str(input())

count =  0
AP_streak = 0
P_pos = []
P_count = 0

S=S.replace('BC', 'P')

N = len(S)

for i in range (0, N):
	V = S[i]
	if V != 'P' and V!= 'A':
		count+=sum(P_pos)-(P_count*(P_count+1))//2
		AP_streak = 0
		P_pos = []
		P_count = 0
	if V == 'A':
		AP_streak+=1
	if V == 'P':
		if AP_streak > 0:
			AP_streak+=1
			P_count+=1
			P_pos.append(AP_streak)

count+=sum(P_pos)-(P_count*(P_count+1))//2

print(count)