S = "???" + input() + "???"

a = 0

ans = 0
i = 0
while i < len(S):
    s = S[i]

    if s == "A":
        a += 1
        i += 1
        while i < len(S):
            s1 = S[i]
            s2 = S[i + 1]

            if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

        a = 0
    else:
        i += 1
        continue

print(ans) S = "???" + input() + "???" S "???" + input() + "???" "???" + input() "???" input() input "???" a = 0 a 0 ans = 0 ans 0 i = 0 i 0 while i < len(S):
    s = S[i]

    if s == "A":
        a += 1
        i += 1
        while i < len(S):
            s1 = S[i]
            s2 = S[i + 1]

            if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

        a = 0
    else:
        i += 1
        continue i < len(S) i len(S) len S s = S[i] s S[i] S i if s == "A":
        a += 1
        i += 1
        while i < len(S):
            s1 = S[i]
            s2 = S[i + 1]

            if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

        a = 0
    else:
        i += 1
        continue s == "A" s "A" a += 1 a 1 i += 1 i 1 while i < len(S):
            s1 = S[i]
            s2 = S[i + 1]

            if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

         i < len(S) i len(S) len S s1 = S[i] s1 S[i] S i s2 = S[i + 1] s2 S[i + 1] S i + 1 i 1 if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

         s1 == "A" s1 "A" a += 1 a 1 i += 1 i 1 continue elif s1 + s2 == "BC":
                ans += a
                i += 2
             s1 + s2 == "BC" s1 + s2 s1 s2 "BC" ans += a ans a i += 2 i 2 break a = 0 a 0 i += 1 i 1 continue print(ans) print ans a = 0 0 a s1 = S[i] S[i] s1 i += 1 1 i i += 1 1 i S = "???" + input() + "???" "???" + input() + "???" S s = S[i] S[i] s a += 1 1 a a = 0 0 a a += 1 1 a i = 0 0 i ans = 0 0 ans s2 = S[i + 1] S[i + 1] s2 i += 1 1 i i += 2 2 i ans += a a ans
S = "???" + input() + "???"

a = 0

ans = 0
i = 0
while i < len(S):
    s = S[i]

    if s == "A":
        a += 1
        i += 1
        while i < len(S):
            s1 = S[i]
            s2 = S[i + 1]

            if s1 == "A":
                a += 1
                i += 1
                continue
            elif s1 + s2 == "BC":
                ans += a
                i += 2
            else:
                break

        a = 0
    else:
        i += 1
        continue

print(ans)
