s = input().strip()
x = [s[0]]
for i in range(1,len(s)):
    if s[i]=="C" and s[i-1]=="B":
        x.pop()
        x.append("T")
    else:
        x.append(s[i])
cnt = 0
ca = 0
for i in range(len(x)):
    if x[i]=="A":
        ca += 1
    elif x[i]=="T":
        cnt += ca
    elif x[i]=="B" or x[i]=="C":
        ca = 0
print(cnt)  s = input().strip() s input().strip() ().strip () input strip x = [s[0]] x [s[0]] s[0] s 0 for i in range(1,len(s)):
    if s[i]=="C" and s[i-1]=="B":
        x.pop()
        x.append("T")
    else:
        x.append(s[i]) i range(1,len(s)) range 1 len(s) len s if s[i]=="C" and s[i-1]=="B":
        x.pop()
        x.append("T")
    else:
        x.append(s[i]) s[i]=="C" and s[i-1]=="B" s[i]=="C" s[i] s i "C" s[i-1]=="B" s[i-1] s i-1 i 1 "B" x.pop() x.pop x pop x.append("T") x.append x append "T" x.append(s[i]) x.append x append s[i] s i cnt = 0 cnt 0 ca = 0 ca 0 for i in range(len(x)):
    if x[i]=="A":
        ca += 1
    elif x[i]=="T":
        cnt += ca
    elif x[i]=="B" or x[i]=="C":
        ca = 0 i range(len(x)) range len(x) len x if x[i]=="A":
        ca += 1
    elif x[i]=="T":
        cnt += ca
    elif x[i]=="B" or x[i]=="C":
        ca = 0 x[i]=="A" x[i] x i "A" ca += 1 ca 1 elif x[i]=="T":
        cnt += ca
     x[i]=="T" x[i] x i "T" cnt += ca cnt ca elif x[i]=="B" or x[i]=="C":
        ca = 0 x[i]=="B" or x[i]=="C" x[i]=="B" x[i] x i "B" x[i]=="C" x[i] x i "C" ca = 0 ca 0 print(cnt) print cnt cnt += ca ca cnt s = input().strip() input().strip() s ca += 1 1 ca x = [s[0]] [s[0]] x ca = 0 0 ca cnt = 0 0 cnt ca = 0 0 ca
s = input().strip()
x = [s[0]]
for i in range(1,len(s)):
    if s[i]=="C" and s[i-1]=="B":
        x.pop()
        x.append("T")
    else:
        x.append(s[i])
cnt = 0
ca = 0
for i in range(len(x)):
    if x[i]=="A":
        ca += 1
    elif x[i]=="T":
        cnt += ca
    elif x[i]=="B" or x[i]=="C":
        ca = 0
print(cnt) 