s=list(eval(input()))

n=len(s)

a=0

b=[]

i=0

def ac(b):

  a=b[::-1]

  t,c=0,0

  for i in range(len(b)):

    if a[i]==0:c+=i-t;t+=1

  return c

while i<n:

  f=True

  if s[i]=="A":b.append(0);f=False

  if i<n-1:

    if s[i]+s[i+1]=="BC":b.append(1);f=False;i+=1

  if f:

    a+=ac(b)

    b=[]

  i+=1

print((a+ac(b)))
s=input().replace("BC","X").replace("B","Y").replace("C","Y")

a=False

ans=0

c=0

for i in "Y"+s+"Y":

	if i=="A":

		a=True

		c+=1

	if i=="X":

		if a:

			ans+=c

	if i=="Y":

		a=False

		c=0

print(ans)
s = list(eval(input()))
n = len(s)
a = 0
b = []
i = 0


def ac(b):
    a = b[::-1]
    t, c = 0, 0
    for i in range(len(b)):
        if a[i] == 0:
            c += i - t
            t += 1
    return c


while i < n:
    f = True
    if s[i] == "A":
        b.append(0)
        f = False
    if i < n - 1:
        if s[i] + s[i + 1] == "BC":
            b.append(1)
            f = False
            i += 1
    if f:
        a += ac(b)
        b = []
    i += 1
print((a + ac(b)))

s = input().replace("BC", "X").replace("B", "Y").replace("C", "Y")
a = False
ans = 0
c = 0
for i in "Y" + s + "Y":
    if i == "A":
        a = True
        c += 1
    if i == "X":
        if a:
            ans += c
    if i == "Y":
        a = False
        c = 0
print(ans)

-s = list(eval(input())) -n = len(s) -a = 0 -b = [] -i = 0 - - -def ac(b): -    a = b[::-1] -    t, c = 0, 0 -    for i in range(len(b)): -        if a[i] == 0: -            c += i - t -            t += 1 -    return c - - -while i < n: -    f = True -    if s[i] == "A": -        b.append(0) -        f = False -    if i < n - 1: -        if s[i] + s[i + 1] == "BC": -            b.append(1) -            f = False -            i += 1 -    if f: -        a += ac(b) -        b = [] -    i += 1 -print((a + ac(b))) +s = input().replace("BC", "X").replace("B", "Y").replace("C", "Y") +a = False +ans = 0 +c = 0 +for i in "Y" + s + "Y": +    if i == "A": +        a = True +        c += 1 +    if i == "X": +        if a: +            ans += c +    if i == "Y": +        a = False +        c = 0 +print(ans)