s=list(input())
l=[]
f=0
for i in range(len(s)-1):
    if s[i]=="A":
        l.append("A")
        f=0
    elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
    else:
        if f:
            f=0
            continue
        else:
            l.append("C")
ac=0
ans=0
for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0
print(ans) s=list(input()) s list(input()) list input() input l=[] l [] f=0 f 0 for i in range(len(s)-1):
    if s[i]=="A":
        l.append("A")
        f=0
    elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
    else:
        if f:
            f=0
            continue
        else:
            l.append("C") i range(len(s)-1) range len(s)-1 len(s) len s 1 if s[i]=="A":
        l.append("A")
        f=0
    elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
    else:
        if f:
            f=0
            continue
        else:
            l.append("C") s[i]=="A" s[i] s i "A" l.append("A") l.append l append "A" f=0 f 0 elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
     s[i]=="B" s[i] s i "B" if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
     s[i+1]=="C" s[i+1] s i+1 i 1 "C" l.append("D") l.append l append "D" f=1 f 1 l.append("B") l.append l append "B" f=0 f 0 if f:
            f=0
            continue
        else:
            l.append("C") f f=0 f 0 continue l.append("C") l.append l append "C" ac=0 ac 0 ans=0 ans 0 for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0 i range(len(l)) range len(l) len l if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0 l[i]=="A" l[i] l i "A" ac+=1 ac 1 elif l[i]=="D":
        ans+=ac
     l[i]=="D" l[i] l i "D" ans+=ac ans ac ac=0 ac 0 print(ans) print ans l=[] [] l ac=0 0 ac ac=0 0 ac f=1 1 f f=0 0 f ac+=1 1 ac ans+=ac ac ans f=0 0 f s=list(input()) list(input()) s ans=0 0 ans f=0 0 f f=0 0 f
s=list(input())
l=[]
f=0
for i in range(len(s)-1):
    if s[i]=="A":
        l.append("A")
        f=0
    elif s[i]=="B":
        if s[i+1]=="C":
            l.append("D")
            f=1
        else:
            l.append("B")
            f=0
    else:
        if f:
            f=0
            continue
        else:
            l.append("C")
ac=0
ans=0
for i in range(len(l)):
    if l[i]=="A":
        ac+=1
    elif l[i]=="D":
        ans+=ac
    else:
        ac=0
print(ans)
