program agc034_b
    use,intrinsic :: iso_fortran_env
    implicit none
    character(200000):: s
    integer(int64):: i,l,ca,ans

    read*, s
    l = len_trim(s)

    i = 1
    ca = 0
    ans=0
    do while(i <= l)
        if (s(i:i+1) == 'BC') then
            ans=ans+ca
            i=i+2
        else if (s(i:i) == 'A') then
            ca=ca+1
            i=i+1
        else
            ca=0
            i=i+1
        end if
    end do
    print'(i0)', ans
end program agc034_b    