s = input()
N = len(s)

# AABC->ABCA->BCAA
# ABCの前にAがn個->ABCの後にAがn個

# ABCABC->BCABCA->BCBCAA

# AかBCでない並びがあったら切断

# Aを右に BCを左に移動させる操作
# BCがあったら、それより左にあるAの数だけansが増える


i = 0
a = 0
ans = 0

while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue
    if s[i] == 'B' and i + 1 < N:
        if s[i + 1] == 'C':
            ans += a
            i += 2
            continue
    a = 0
    i += 1

print(ans) s = input() s input() input N = len(s) N len(s) len s i = 0 i 0 a = 0 a 0 ans = 0 ans 0 while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue
    if s[i] == 'B' and i + 1 < N:
        if s[i + 1] == 'C':
            ans += a
            i += 2
            continue
    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 + 1 < N:
        if s[i + 1] == 'C':
            ans += a
            i += 2
            continue
     s[i] == 'B' and i + 1 < N s[i] == 'B' s[i] s i 'B' i + 1 < N i + 1 i 1 N if s[i + 1] == 'C':
            ans += a
            i += 2
            continue
     s[i + 1] == 'C' s[i + 1] s i + 1 i 1 'C' ans += a ans a i += 2 i 2 continue a = 0 a 0 i += 1 i 1 print(ans) print ans i += 2 2 i ans += a a ans i = 0 0 i a = 0 0 a s = input() input() s i += 1 1 i a = 0 0 a i += 1 1 i a += 1 1 a N = len(s) len(s) N ans = 0 0 ans
s = input()
N = len(s)

# AABC->ABCA->BCAA
# ABCの前にAがn個->ABCの後にAがn個

# ABCABC->BCABCA->BCBCAA

# AかBCでない並びがあったら切断

# Aを右に BCを左に移動させる操作
# BCがあったら、それより左にあるAの数だけansが増える


i = 0
a = 0
ans = 0

while i < len(s):
    if s[i] == 'A':
        a += 1
        i += 1
        continue
    if s[i] == 'B' and i + 1 < N:
        if s[i + 1] == 'C':
            ans += a
            i += 2
            continue
    a = 0
    i += 1

print(ans)
