output_description: Find the maximum possible number of operations.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      s
attempt: #!/usr/bin/env python3
  ##### Binary Indexed Tree #####
  class Bit:
      def __init__(self, n):
          self.size = n
          self.tree = [0] * (n + 1)
  
      def __iter__(self):
          psum = 0
          for i in range(self.size):
              csum = self.sum(i + 1)
              yield csum - psum
              psum = csum
          raise StopIteration()
  
      def __str__(self):  # O(nlogn)
          return str(list(self))
  
      def sum(self, i):
          # [0, i) の要素の総和を返す
          if not (0 <= i <= self.size):
              raise ValueError("error!")
          s = 0
          while i > 0:
              s += self.tree[i]
              i -= i & -i
          return s
  
      def add(self, i, x):
          if not (0 <= i < self.size):
              raise ValueError("error!")
          i += 1
          while i <= self.size:
              self.tree[i] += x
              i += i & -i
  
      def __getitem__(self, key):
          if not (0 <= key < self.size):
              raise IndexError("error!")
          return self.sum(key + 1) - self.sum(key)
  
      def __setitem__(self, key, value):
          # 足し算と引き算にはaddを使うべき
          if not (0 <= key < self.size):
              raise IndexError("error!")
          self.add(key, value - self[key])
  
  
  # 転倒数
  def mergecount(A: list):
      if not A:
          return 0
      bit = Bit(max(A) + 1)
      cnt = 0
      for i, a in enumerate(A):
          cnt += i - bit.sum(a + 1)
          bit.add(a, 1)
      return cnt
  
  
  import re
  
  print(
      sum(
          mergecount([*map(int, i)])
          for i in re.split("[BC]", input().replace("A", "1").replace("BC", "0"))
      )
  )
  
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"}]