A  = 1
BC = 2
X  = 3

s = gets.chomp
a = []

i = 0
while i < s.size
  if s[i] == 'A'
    a << A
    i += 1
  elsif s[i] == 'B' && s[i+1] == 'C'
    a << BC
    i += 2
  else
    a << X
    i += 1
  end
end

b = []
tmp = []

a.each do |elm|
  if elm == X
    b << tmp
    tmp = []
  else
    tmp << elm
  end
end

b << tmp
b.reject!(&:empty?)

total = 0

b.each do |cs|
  num_a = 0
  point = 0
  cs.each do |c|
    if c == A
      num_a += 1
    elsif c == BC
      point += num_a
    end
  end

  total += point
end

p total
