s = raw_input()

count = 0
a = 0
i = 0
l = len(s)
while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue

    if s[i] == 'B' and i < l - 1 and s[i + 1] == 'C':
        count += a
        i += 2
    else:
        a = 0
        i += 1

print count s = raw_input() s raw_input() raw_input count = 0 count 0 a = 0 a 0 i = 0 i 0 l = len(s) l len(s) len s while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue

    if s[i] == 'B' and i < l - 1 and s[i + 1] == 'C':
        count += a
        i += 2
    else:
        a = 0
        i += 1 i < len(s) i len(s) len s if s[i] == 'A':
        a += 1
        i += 1
        continue

     s[i] == 'A' s[i] s i 'A' a += 1 a 1 i += 1 i 1 continue if s[i] == 'B' and i < l - 1 and s[i + 1] == 'C':
        count += a
        i += 2
    else:
        a = 0
        i += 1 s[i] == 'B' and i < l - 1 and s[i + 1] == 'C' s[i] == 'B' and i < l - 1 s[i] == 'B' s[i] s i 'B' i < l - 1 i l - 1 l 1 s[i + 1] == 'C' s[i + 1] s i + 1 i 1 'C' count += a count a i += 2 i 2 a = 0 a 0 i += 1 i 1 print a += 1 1 a i += 1 1 i a = 0 0 a a = 0 0 a i += 1 1 i count += a a count i = 0 0 i i += 2 2 i s = raw_input() raw_input() s l = len(s) len(s) l count = 0 0 count
s = raw_input()

count = 0
a = 0
i = 0
l = len(s)
while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue

    if s[i] == 'B' and i < l - 1 and s[i + 1] == 'C':
        count += a
        i += 2
    else:
        a = 0
        i += 1

print count
