
        
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    s = s.replace('BC', 'D')
    n = len(s)
    i = 0
    ans = 0
    while i < n:
        while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
        st = i
        cnt = 0
        while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
        ed = i
        for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
    print(ans)

    
    


                
if __name__ == '__main__':
    main() def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    s = s.replace('BC', 'D')
    n = len(s)
    i = 0
    ans = 0
    while i < n:
        while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
        st = i
        cnt = 0
        while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
        ed = i
        for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
    print(ans)

    
    


                 main import sys sys def input(): return sys.stdin.readline().rstrip()

     input s = input() s input() input s = s.replace('BC', 'D') s s.replace('BC', 'D') s.replace s replace 'BC' 'D' n = len(s) n len(s) len s i = 0 i 0 ans = 0 ans 0 while i < n:
        while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
        st = i
        cnt = 0
        while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
        ed = i
        for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
     i < n i n while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
         i < n and (s[i] == 'B' or s[i]=='C') i < n i n s[i] == 'B' or s[i]=='C' s[i] == 'B' s[i] s i 'B' s[i]=='C' s[i] s i 'C' i += 1 i 1 st = i st i cnt = 0 cnt 0 while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
         i < n and (s[i] == 'A' or s[i]=='D') i < n i n s[i] == 'A' or s[i]=='D' s[i] == 'A' s[i] s i 'A' s[i]=='D' s[i] s i 'D' if s[i] == 'A':
                cnt += 1
             s[i] == 'A' s[i] s i 'A' cnt += 1 cnt 1 i += 1 i 1 ed = i ed i for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
     j range(st, ed) range st ed if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
     s[j] == 'A' s[j] s j 'A' cnt -= 1 cnt 1 ans +=ed-j-cnt-1 ans ed-j-cnt-1 ed-j-cnt ed-j ed j cnt 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    s = s.replace('BC', 'D')
    n = len(s)
    i = 0
    ans = 0
    while i < n:
        while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
        st = i
        cnt = 0
        while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
        ed = i
        for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
    print(ans)

    
    


                 def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    s = s.replace('BC', 'D')
    n = len(s)
    i = 0
    ans = 0
    while i < n:
        while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
        st = i
        cnt = 0
        while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
        ed = i
        for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
    print(ans)

    
    


                 main

        
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    s = s.replace('BC', 'D')
    n = len(s)
    i = 0
    ans = 0
    while i < n:
        while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
        st = i
        cnt = 0
        while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
        ed = i
        for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
    print(ans)

    
    


                
if __name__ == '__main__':
    main()