import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main():
    s = list(input())
    
    cnt = 0
    ans = 0
    if len(s) < 3:
        print(0)
        exit()

    i = len(s) - 1
    while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

    print(ans)
if __name__=='__main__':
    main() import sys sys INF = 10 ** 9 INF 10 ** 9 10 9 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 from collections import deque sys.setrecursionlimit(100000000) sys.setrecursionlimit sys setrecursionlimit 100000000 def main():
    s = list(input())
    
    cnt = 0
    ans = 0
    if len(s) < 3:
        print(0)
        exit()

    i = len(s) - 1
    while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

    print(ans) main s = list(input()) s list(input()) list input() input cnt = 0 cnt 0 ans = 0 ans 0 if len(s) < 3:
        print(0)
        exit()

     len(s) < 3 len(s) len s 3 print(0) print 0 exit() exit i = len(s) - 1 i len(s) - 1 len(s) len s 1 while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

     i > 0 i 0 while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

     i > 0 and s[i-1] == 'B' and s[i] == 'C' i > 0 and s[i-1] == 'B' i > 0 i 0 s[i-1] == 'B' s[i-1] s i-1 i 1 'B' s[i] == 'C' s[i] s i 'C' cnt += 1 cnt 1 i -= 2 i 2 while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
         i >= 0 and s[i] == 'A' i >= 0 i 0 s[i] == 'A' s[i] s i 'A' ans += cnt ans cnt i -= 1 i 1 cnt = 0 cnt 0 i -= 1 i 1 print(ans) print ans if __name__=='__main__':
    main() __name__=='__main__' __name__ '__main__' main() main def main():
    s = list(input())
    
    cnt = 0
    ans = 0
    if len(s) < 3:
        print(0)
        exit()

    i = len(s) - 1
    while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

    print(ans) def main():
    s = list(input())
    
    cnt = 0
    ans = 0
    if len(s) < 3:
        print(0)
        exit()

    i = len(s) - 1
    while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

    print(ans) main INF = 10 ** 9 10 ** 9 INF MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main():
    s = list(input())
    
    cnt = 0
    ans = 0
    if len(s) < 3:
        print(0)
        exit()

    i = len(s) - 1
    while i > 0:
        while i > 0 and s[i-1] == 'B' and s[i] == 'C':
            cnt += 1
            i -= 2  
            while i >= 0 and s[i] == 'A':
                ans += cnt
                i -= 1
        else:
            cnt = 0
            i -= 1

    print(ans)
if __name__=='__main__':
    main()
