s = gets.chomp
cnt = 0
while true
  ss = s.clone
  ss = ss.gsub(/BC/,'?')

  while ss.count('?') > 0
    i = ss.index('?')
    ii = ss.index(/A+\?/)
    if ii.nil?
      ss.gsub!(/\?/,'BC')
      break
    elsif i > ii
      cnt += i - ii
      iii = i - ii
      t = 'BC' * iii + 'A'
      ss[ii..i] = t
    elsif i < ii
      s[i] = 'BC'
    end
  end

  if s == ss
    break
  else
    s = ss
  end
end

puts cnt
