s = gets.chomp
cnt = 0
while true
  ss = s.clone
  ss = ss.gsub(/AAABCBC/,'[')#6
  ss = ss.gsub(/AABCBC/,']') #4
  ss = ss.gsub(/ABCABC/,'+') #3
  ss = ss.gsub(/ABCBC/,'*')  #2
  ss = ss.gsub(/ABC/,'?')    #1

  if ss.count('[') > 0
    cnt += ss.count('[')*6
    ss.gsub!(/\[/,'BCBCAAA')
  end

  if ss.count(']') > 0
    cnt += ss.count(']')*4
    ss.gsub!(/\]/,'BCBCAA')
  end

  if ss.count('+') > 0
    cnt += ss.count('+')*3
    ss.gsub!(/\+/,'BCBCAA')
  end

  if ss.count('*') > 0
    cnt += ss.count('*')*2
    ss.gsub!(/\*/,'BCBCA')
  end

  if ss.count('?') > 0
    cnt += ss.count('?')
    ss.gsub!(/\?/,'BCA')
  end

  if s == ss
    break
  else
    s = ss.clone
  end
end

puts cnt
