s = gets.chomp
 
sum = 0
while true do
    count  = 4 * s.scan("AABCBC").size
    s.gsub!("AABCBC", "BCBCAA")

    count += 3 * s.scan("ABCABC").size
    s.gsub!("ABCABC", "BCBCAA")

    count += s.scan("ABC").size
    break if count == 0

    sum += count
    s.gsub!("ABC", "BCA")
end

puts sum
