import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
cur = 'D'
answer = 0
A_cnt = 0
for s in S:
    if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D'

print(answer) import sys sys stdin = sys.stdin stdin sys.stdin sys stdin ri = lambda: int(rs()) ri lambda: int(rs()) int(rs()) int rs() rs rl = lambda: list(map(int, stdin.readline().split())) rl lambda: list(map(int, stdin.readline().split())) list(map(int, stdin.readline().split())) list map(int, stdin.readline().split()) map int stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split rs = lambda: stdin.readline().rstrip() rs lambda: stdin.readline().rstrip() stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip S = list(rs()) S list(rs()) list rs() rs cur = 'D' cur 'D' answer = 0 answer 0 A_cnt = 0 A_cnt 0 for s in S:
    if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D' s S if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D' cur == 'A' cur 'A' if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
     s == 'A' s 'A' A_cnt += 1 A_cnt 1 elif s == 'B':
            cur = s
         s == 'B' s 'B' cur = s cur s cur = 'D' cur 'D' A_cnt = 0 A_cnt 0 elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
     cur == 'B' cur 'B' if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
     s == 'A' s 'A' A_cnt = 1 A_cnt 1 cur = s cur s elif s == 'B':
            A_cnt = 0
            cur = 'D'
         s == 'B' s 'B' A_cnt = 0 A_cnt 0 cur = 'D' cur 'D' elif s == 'C':
            answer += A_cnt
            cur = s
         s == 'C' s 'C' answer += A_cnt answer A_cnt cur = s cur s cur = 'D' cur 'D' A_cnt = 0 A_cnt 0 elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
     cur == 'C' cur 'C' if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
     s == 'A' s 'A' A_cnt += 1 A_cnt 1 cur = s cur s elif s == 'B':
            cur = s
         s == 'B' s 'B' cur = s cur s cur = 'D' cur 'D' A_cnt = 0 A_cnt 0 if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D' s == 'A' s 'A' A_cnt += 1 A_cnt 1 cur = s cur s A_cnt = 0 A_cnt 0 cur = 'D' cur 'D' print(answer) print answer rl = lambda: list(map(int, stdin.readline().split())) lambda: list(map(int, stdin.readline().split())) rl A_cnt = 0 0 A_cnt A_cnt += 1 1 A_cnt cur = 'D' 'D' cur answer = 0 0 answer A_cnt = 1 1 A_cnt cur = 'D' 'D' cur A_cnt = 0 0 A_cnt cur = 'D' 'D' cur cur = 'D' 'D' cur stdin = sys.stdin sys.stdin stdin A_cnt = 0 0 A_cnt A_cnt = 0 0 A_cnt cur = s s cur answer += A_cnt A_cnt answer ri = lambda: int(rs()) lambda: int(rs()) ri cur = s s cur A_cnt = 0 0 A_cnt cur = s s cur cur = s s cur cur = s s cur A_cnt += 1 1 A_cnt A_cnt = 0 0 A_cnt cur = s s cur S = list(rs()) list(rs()) S rs = lambda: stdin.readline().rstrip() lambda: stdin.readline().rstrip() rs A_cnt += 1 1 A_cnt cur = 'D' 'D' cur cur = 'D' 'D' cur
import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
cur = 'D'
answer = 0
A_cnt = 0
for s in S:
    if cur == 'A':
        if s == 'A':
            A_cnt += 1
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'B':
        if s == 'A':
            A_cnt = 1
            cur = s
        elif s == 'B':
            A_cnt = 0
            cur = 'D'
        elif s == 'C':
            answer += A_cnt
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    elif cur == 'C':
        if s == 'A':
            A_cnt += 1
            cur = s
        elif s == 'B':
            cur = s
        else:
            cur = 'D'
            A_cnt = 0
    else:
        if s == 'A':
            A_cnt += 1
            cur = s
        else:
            A_cnt = 0
            cur = 'D'

print(answer)
