s = input()
s = s.replace("BC", "D")
result = 0
i = 0
while i < len(s)-1:
    if s[i]=="A":
        y = 1
        for j in range(i+1, len(s)):
            i += 1
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
    else:
        i += 1
print(result) s = input() s input() input s = s.replace("BC", "D") s s.replace("BC", "D") s.replace s replace "BC" "D" result = 0 result 0 i = 0 i 0 while i < len(s)-1:
    if s[i]=="A":
        y = 1
        for j in range(i+1, len(s)):
            i += 1
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
    else:
        i += 1 i < len(s)-1 i len(s)-1 len(s) len s 1 if s[i]=="A":
        y = 1
        for j in range(i+1, len(s)):
            i += 1
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
    else:
        i += 1 s[i]=="A" s[i] s i "A" y = 1 y 1 for j in range(i+1, len(s)):
            i += 1
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
     j range(i+1, len(s)) range i+1 i 1 len(s) len s i += 1 i 1 if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
     s[j]=="A" s[j] s j "A" y += 1 y 1 elif s[j]=="D":
                result += y
             s[j]=="D" s[j] s j "D" result += y result y break i += 1 i 1 print(result) print result i += 1 1 i y = 1 1 y result = 0 0 result y += 1 1 y s = s.replace("BC", "D") s.replace("BC", "D") s i += 1 1 i result += y y result i = 0 0 i s = input() input() s
s = input()
s = s.replace("BC", "D")
result = 0
i = 0
while i < len(s)-1:
    if s[i]=="A":
        y = 1
        for j in range(i+1, len(s)):
            i += 1
            if s[j]=="A":
                y += 1
            elif s[j]=="D":
                result += y
            else:
                break
    else:
        i += 1
print(result)