program abc
  implicit none
  character(200000) :: s
  integer :: x(200000), a, n, m, i
  x = -1
  read(*,*) s
  s = trim(adjustl(s))
  n = len_trim(s)
  if (n.lt.3) then
    write(*,'(i0)') 0
    stop
  end if
  i = 1
  m = 0
  do while (i.le.n)
    m = m + 1
    if (s(i:i).eq."A") then
      x(m) = 1
    else if ((i.le.n-1).and.(s(i:i+1).eq."BC")) then
      x(m) = 0
      i = i+1
    end if
    i = i+1
  end do
  n = m
  m = 0
  a = 0
  i = 1
  do i = 1, n
    select case(x(i))
      case(-1)
        a = 0
      case(0)
        m = m+a
      case(1)
        a = a+1
    end select
  end do
  write(*,'(i0)') m
  stop
end program abc