s = input()
l = s.replace("BC","D").replace("B"," ")
L = l.replace("C"," ").split()
ans = 0
for i in L:
    numa = 0
    for j in i:
        if j == "A":
            numa += 1
        else:
            ans += numa
print(ans) s = input() s input() input l = s.replace("BC","D").replace("B"," ") l s.replace("BC","D").replace("B"," ") s.replace("BC","D").replace s.replace("BC","D") s.replace s replace "BC" "D" replace "B" " " L = l.replace("C"," ").split() L l.replace("C"," ").split() l.replace("C"," ").split l.replace("C"," ") l.replace l replace "C" " " split ans = 0 ans 0 for i in L:
    numa = 0
    for j in i:
        if j == "A":
            numa += 1
        else:
            ans += numa i L numa = 0 numa 0 for j in i:
        if j == "A":
            numa += 1
        else:
            ans += numa j i if j == "A":
            numa += 1
        else:
            ans += numa j == "A" j "A" numa += 1 numa 1 ans += numa ans numa print(ans) print ans numa += 1 1 numa numa = 0 0 numa L = l.replace("C"," ").split() l.replace("C"," ").split() L s = input() input() s ans += numa numa ans l = s.replace("BC","D").replace("B"," ") s.replace("BC","D").replace("B"," ") l ans = 0 0 ans
s = input()
l = s.replace("BC","D").replace("B"," ")
L = l.replace("C"," ").split()
ans = 0
for i in L:
    numa = 0
    for j in i:
        if j == "A":
            numa += 1
        else:
            ans += numa
print(ans)