s = gets.chomp

s.gsub!(/BC/, "D")

k = s.split(/[BC]++/)

count = 0

# p k

# k.each{ |str|
#   str.length.times{ |i|
#     if str[i] == "A" then
#       count += str[i...str.length].count("D")
#     end
#   }
# }

k.each{|str|
  str.length.times{|i|
    if (i = str[i...str.length].index("A")) != nil then
      count += str[i...str.length].count("D")
    end
  }
}

p count
