program main
  implicit none
  integer(8) i, sosa, rensa, N
  character(200000) s 
  read(*, *) s
  N = len_trim(s)
  if (N < 3) then
    sosa = 0
  else
    sosa = 0
    rensa = 0
    do !while(i < N-2)
      if (s(i:i) == 'A') then
        rensa = rensa + 1
      else
        rensa = 0
      endif
      if (rensa > 0 .and. s(i+1:i+2) == 'BC') then
        sosa = sosa + rensa
        rensa = rensa-1
        s(i+2:i+2) = 'A'
        i = i+2
      else
        i = i+1
      end if
      if (i > N-2) then
        exit
      end if
    end do
  end if
  write(* ,*) sosa
end program main