s=gets.chomp.reverse
s.gsub!('CB', 'D')
i = 0
n=0
r=0
while i = s.index('A', i)
  n=0
  if i > 0
    ii = i
    while s[ii-1] == 'D'
      ii -= 1
      n+=1
      break if ii < 0
    end
  end
  r+=n
  s.slice!(i)
end
p r