s = input()
ans = 0
a = 0
i = 0
while i < len(s):
    c = s[i]
    if c == 'A':
        a += 1
    elif c == 'B':
        i += 1
        if i >= len(s):
            break
        c = s[i]
        if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
    elif c == 'C':
        a = 0
    i += 1
print(ans) s = input() s input() input ans = 0 ans 0 a = 0 a 0 i = 0 i 0 while i < len(s):
    c = s[i]
    if c == 'A':
        a += 1
    elif c == 'B':
        i += 1
        if i >= len(s):
            break
        c = s[i]
        if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
    elif c == 'C':
        a = 0
    i += 1 i < len(s) i len(s) len s c = s[i] c s[i] s i if c == 'A':
        a += 1
    elif c == 'B':
        i += 1
        if i >= len(s):
            break
        c = s[i]
        if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
    elif c == 'C':
        a = 0
     c == 'A' c 'A' a += 1 a 1 elif c == 'B':
        i += 1
        if i >= len(s):
            break
        c = s[i]
        if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
     c == 'B' c 'B' i += 1 i 1 if i >= len(s):
            break
         i >= len(s) i len(s) len s break c = s[i] c s[i] s i if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
     c == 'C' c 'C' ans += a ans a elif c == 'A':
            a = 1
         c == 'A' c 'A' a = 1 a 1 a = 0 a 0 elif c == 'C':
        a = 0
     c == 'C' c 'C' a = 0 a 0 i += 1 i 1 print(ans) print ans c = s[i] s[i] c a = 0 0 a ans = 0 0 ans a = 1 1 a a = 0 0 a s = input() input() s c = s[i] s[i] c a += 1 1 a a = 0 0 a ans += a a ans i = 0 0 i i += 1 1 i i += 1 1 i
s = input()
ans = 0
a = 0
i = 0
while i < len(s):
    c = s[i]
    if c == 'A':
        a += 1
    elif c == 'B':
        i += 1
        if i >= len(s):
            break
        c = s[i]
        if c == 'C':
            ans += a
        elif c == 'A':
            a = 1
        else:
            a = 0
    elif c == 'C':
        a = 0
    i += 1
print(ans)
