# map(int, input().split())
# list(map(int, input().split()))
# for _ in range(int(input())):
# print(' '.join([str(x) for x in ans]))

s = input()

numBC = 0
total = 0
i = len(s)-1
while i >= 0:    
    if s[i] == 'A':
        total += numBC
    elif s[i] == 'C' and i > 0 and s[i-1] == 'B':
            numBC += 1
            i -= 1
    else:
        numBC = 0
    i-=1

print(total)
 s = input() s input() input numBC = 0 numBC 0 total = 0 total 0 i = len(s)-1 i len(s)-1 len(s) len s 1 while i >= 0:    
    if s[i] == 'A':
        total += numBC
    elif s[i] == 'C' and i > 0 and s[i-1] == 'B':
            numBC += 1
            i -= 1
    else:
        numBC = 0
    i-=1 i >= 0 i 0 if s[i] == 'A':
        total += numBC
    elif s[i] == 'C' and i > 0 and s[i-1] == 'B':
            numBC += 1
            i -= 1
    else:
        numBC = 0
     s[i] == 'A' s[i] s i 'A' total += numBC total numBC elif s[i] == 'C' and i > 0 and s[i-1] == 'B':
            numBC += 1
            i -= 1
     s[i] == 'C' and i > 0 and s[i-1] == 'B' s[i] == 'C' and i > 0 s[i] == 'C' s[i] s i 'C' i > 0 i 0 s[i-1] == 'B' s[i-1] s i-1 i 1 'B' numBC += 1 numBC 1 i -= 1 i 1 numBC = 0 numBC 0 i-=1 i 1 print(total) print total numBC = 0 0 numBC s = input() input() s total += numBC numBC total i-=1 1 i numBC += 1 1 numBC i = len(s)-1 len(s)-1 i numBC = 0 0 numBC total = 0 0 total i -= 1 1 i
# map(int, input().split())
# list(map(int, input().split()))
# for _ in range(int(input())):
# print(' '.join([str(x) for x in ans]))

s = input()

numBC = 0
total = 0
i = len(s)-1
while i >= 0:    
    if s[i] == 'A':
        total += numBC
    elif s[i] == 'C' and i > 0 and s[i-1] == 'B':
            numBC += 1
            i -= 1
    else:
        numBC = 0
    i-=1

print(total)

