def main():
    s = input()
    s = s.replace('BC', 'D')
    a = 0; d = 0
    ans = 0
    for t in s:
        if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
        a += (t == 'A')
    if a > 0 and d > 0:
        ans += a*d
    print(ans)

if __name__ == "__main__":
    main() def main():
    s = input()
    s = s.replace('BC', 'D')
    a = 0; d = 0
    ans = 0
    for t in s:
        if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
        a += (t == 'A')
    if a > 0 and d > 0:
        ans += a*d
    print(ans) main s = input() s input() input s = s.replace('BC', 'D') s s.replace('BC', 'D') s.replace s replace 'BC' 'D' a = 0 a 0 d = 0 d 0 ans = 0 ans 0 for t in s:
        if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
        a += (t == 'A')
     t s if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
         a > 0 a 0 if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
         t == 'D' t 'D' d += 1 d 1 elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
             t == 'A' t 'A' if d > 0:
                    ans += a*d
                    d = 0
             d > 0 d 0 ans += a*d ans a*d a d d = 0 d 0 elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
             t != 'D' and d > 0 t != 'D' t 'D' d > 0 d 0 ans += a*d ans a*d a d a = 0 a 0 d = 0 d 0 a = 0 a 0 d = 0 d 0 a += (t == 'A') a t == 'A' t 'A' if a > 0 and d > 0:
        ans += a*d
     a > 0 and d > 0 a > 0 a 0 d > 0 d 0 ans += a*d ans a*d a d print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    s = input()
    s = s.replace('BC', 'D')
    a = 0; d = 0
    ans = 0
    for t in s:
        if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
        a += (t == 'A')
    if a > 0 and d > 0:
        ans += a*d
    print(ans) def main():
    s = input()
    s = s.replace('BC', 'D')
    a = 0; d = 0
    ans = 0
    for t in s:
        if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
        a += (t == 'A')
    if a > 0 and d > 0:
        ans += a*d
    print(ans) main
def main():
    s = input()
    s = s.replace('BC', 'D')
    a = 0; d = 0
    ans = 0
    for t in s:
        if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
        a += (t == 'A')
    if a > 0 and d > 0:
        ans += a*d
    print(ans)

if __name__ == "__main__":
    main()
