from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    s = input()
    s = s.replace("BC", "P")
    s = s.replace("B", "T")
    s = s.replace("C", "T")
    s = s.split("T")
    ans = 0
    for ss in s:
        p = 0
        for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
    print(ans)





    


if __name__ == '__main__':
    main() from fractions import gcd from datetime import date, timedelta from heapq import* import math math from collections import defaultdict, Counter, deque import sys sys from bisect import * import itertools itertools import copy copy sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 def main():
    s = input()
    s = s.replace("BC", "P")
    s = s.replace("B", "T")
    s = s.replace("C", "T")
    s = s.split("T")
    ans = 0
    for ss in s:
        p = 0
        for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
    print(ans)





     main s = input() s input() input s = s.replace("BC", "P") s s.replace("BC", "P") s.replace s replace "BC" "P" s = s.replace("B", "T") s s.replace("B", "T") s.replace s replace "B" "T" s = s.replace("C", "T") s s.replace("C", "T") s.replace s replace "C" "T" s = s.split("T") s s.split("T") s.split s split "T" ans = 0 ans 0 for ss in s:
        p = 0
        for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
     ss s p = 0 p 0 for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
     i range(len(ss) - 1, -1 ,-1) range len(ss) - 1 len(ss) len ss 1 -1 -1 if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
     ss[i] == 'P' ss[i] ss i 'P' p += 1 p 1 elif ss[i] == 'A':
                ans += p
     ss[i] == 'A' ss[i] ss i 'A' ans += p ans p print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def main():
    s = input()
    s = s.replace("BC", "P")
    s = s.replace("B", "T")
    s = s.replace("C", "T")
    s = s.split("T")
    ans = 0
    for ss in s:
        p = 0
        for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
    print(ans)





     def main():
    s = input()
    s = s.replace("BC", "P")
    s = s.replace("B", "T")
    s = s.replace("C", "T")
    s = s.split("T")
    ans = 0
    for ss in s:
        p = 0
        for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
    print(ans)





     main
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    s = input()
    s = s.replace("BC", "P")
    s = s.replace("B", "T")
    s = s.replace("C", "T")
    s = s.split("T")
    ans = 0
    for ss in s:
        p = 0
        for i in range(len(ss) - 1, -1 ,-1):
            if ss[i] == 'P':
                p += 1
            elif ss[i] == 'A':
                ans += p
    print(ans)





    


if __name__ == '__main__':
    main()
