program abc
  implicit none
  character(200000) :: s
  integer :: x(200000), a(3), b(3), n, m, i
  x = 0
  a = (/-1,0,1/)
  b = (/0,1,-1/)
  read(*,*) s
  s = trim(adjustl(s))
  n = len_trim(s)
  if (n.lt.3) then
    write(*,'(i0)') 0
    stop
  end if
  do i = 1, n
    x(i) = ichar(s(i:i))-66
  end do
  m = 0
  i = 1
  do while (i.le.n-2)
    if ((x(i).eq.-1).and.(x(i+1).eq.0).and.(x(i+2).eq.1)) then
      x(i:i+2) = b
      m = m+1
      i = max(1,i-1)
    else
      i = i+1
    end if
  end do
  write(*,'(i0)') m
  stop
end program abc