output_description: Find the maximum possible number of operations.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      s
attempt: from sys import stdin
  
  s = stdin.readline().rstrip()
  l = []
  
  for i in range(len(s) - 2):
      if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
          l.append(i)
  
  # print(l)
  
  ll = []
  count = 0
  
  
  def souwa(n):
      sum = 0
      while 0 < n:
          sum += n
          n -= 1
      return sum
  
  
  for i in range(len(l)):
      # 前にaがあればcount
      if l[i] > 0:
          j = l[i] - 1
          while 0 <= j:
              if s[j] != "A":
                  break
              count += 1
              j -= 1
  
      # うしろにbcがあればcount
      j = l[i] + 3
      while j < len(s) - 1:
          if s[j] != "B" or s[j + 1] != "C":
              break
          count += 1
          j += 2
  
  
  # print(l, count)
  
  for i in range(len(l)):
      if l[i] < 0:
          continue
      join = 0
      j = i + 1
      while j < len(l):
          # print(l[j-1], l[j])
          if l[j - 1] == (l[j] - 3):
              join += 1
              j += 1
              continue
          k = l[j - 1] + 3
          # print (k, s[k], s[k+1])
          while k < len(s) - 1:
              if s[k] != "B" or s[k + 1] != "C":
                  break
              k += 2
          # print ("BC CHECK", k, l[j])
          if k == l[j]:
              # print("BC JOIN")
              join += 1
              j += 1
              continue
          while k < l[j]:
              if s[k] != "A":
                  break
              k += 1
          # print ("A CHECK", k, l[j])
          if k == l[j]:
              # print("A JOIN")
              join += 1
              j += 1
              continue
          break
  
      count += souwa(join + 1)
      # print("COUNT", count, join+1)
      while 0 < join:
          l[i + join] = -1
          join -= 1
  
  print(count)
  
problem_description: Statement
  
  You are given a string s consisting of `A`, `B` and `C`.
  
  Snuke wants to perform the following operation on s as many times as possible:
  
    * Choose a contiguous substring of s that reads `ABC` and replace it with `BCA`.
  
  Find the maximum possible number of operations.
samples: [{"input": "ABCABC", "output": "3\n    \n\nYou can perform the operations three times as follows: `ABCABC` \u2192 `BCAABC` \u2192\n`BCABCA` \u2192 `BCBCAA`. This is the maximum result.\n\n* * *"}, {"input": "C", "output": "0\n    \n\n* * *"}, {"input": "ABCACCBABCBCAABCB", "output": "6"}]