Problem:
 Score : 600 points    Problem 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.      Constraints  1 \leq |s| \leq 200000  Each character of s is A , B and C .         Input Input is given from Standard Input in the following format:  s       Output Find the maximum possible number of operations.        Sample Input 1 ABCABC      Sample Output 1 3  You can perform the operations three times as follows: ABCABC → BCAABC → BCABCA → BCBCAA . This is the maximum result.       Sample Input 2 C      Sample Output 2 0       Sample Input 3 ABCACCBABCBCAABCB      Sample Output 3 6

Solution (Python):
s = input()
ans = 0
tmp = 0
i = 0
while i < len(s)-1:
    if s[i] == "A":
        tmp += 1
    elif s[i] == "B":
        if s[i+1] == "C":
            ans += tmp
            i += 1
        else:
            tmp = 0
    else:
        tmp = 0
    i += 1
print(ans)

Solution (Python):
S = input()

cnt = 0
ans = 0
n = 0
len_S = len(S)

while n < len_S:
  if S[n]== "A":
    cnt += 1
  elif S[n] == "B":
    if n < len_S-1:
      if S[n+1] == "C":
        ans += cnt
        n += 1
      else:
        cnt = 0
  else:
    cnt = 0
  n += 1
print(ans)

Solution (Python):

def resolve():
    S = input()

    rep_S = S.replace("BC", "D")
    cnt = 0
    ans = 0
    for i in range(len(rep_S)):
        if rep_S[i] == "A":
            cnt += 1
        elif rep_S[i] == "D":
            ans += cnt
        else:
            cnt = 0

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
import sys, math, re
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

s = input()
s = s.replace('BC', 'D')
matches = re.findall(r'[AD]+', s)
ans = 0
for w in matches:
    n = len(w)
    p = n-1
    for i in range(n-1, -1, -1):
        if w[i] == 'A':
            ans += p-i
            p -= 1

print(ans)

Solution (Python):






s = input()





s_ = s.replace("BC","D")
cnt = 0
ans = 0
for i in range(len(s_)):
    if s_[i] == "A":
        cnt += 1
    elif s_[i] == "D":
        ans += cnt
    else:
        cnt = 0
print(ans)

Solution (Python):
s = input()
s = s.replace('BC','D')
A_count = 0
ans = 0

for i in s:
    if i == 'A':
        A_count += 1
    elif i == 'B' or i == 'C':
        A_count = 0
    else:
        ans += A_count
print(ans)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    ans = 0
    stack = []
    for c in input():
        if len(stack) >= 2 and stack[-2:] == ["A", "B"] and c == 'C':
            ans += len(stack) - 1
            stack.pop()
        elif len(stack) >= 1 and stack[-1] == 'A' and c in ('A', 'B'):
            stack.append(c)
        elif c == 'A':
            stack = ['A']
        else:
            stack = []
    print(ans)
resolve()

Solution (Python):
S = input()
s = S.replace("BC", "X")
ans = 0
a = 0
for c in s:
    if c == "A":
        a += 1
    elif c == "X":
        ans += a
    else:
        a = 0

print(ans)

Solution (Python):
S=input()
N=len(S)
i=0
now=0
ans=0
while i<N:
    if S[i]=='A':
        now+=1
    elif S[i:i+2]=='BC':
        ans+=now
        i+=1
    else:
        now=0
    i+=1
print(ans)

Solution (Python):
def main():
    s = input()
    s = s.replace('BC', 'D')
    a = 0; d = 0
    ans = 0
    for t in s:
        if a > 0:
            if t == 'D':
                d += 1
            elif t == 'A':
                if d > 0:
                    ans += a*d
                    d = 0
            elif t != 'D' and d > 0:
                ans += a*d
                a = 0
                d = 0
            else:
                a = 0
                d = 0
        a += (t == 'A')
    if a > 0 and d > 0:
        ans += a*d
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))



S=input()
N=len(S)
ans=0
i=0
a=0
while i<N:
    if S[i]=='A':
        a+=1
        i+=1
    elif i<N-1 and S[i]=='B' and S[i+1]=='C':
        ans+=a
        i+=2
    else:
        a=0
        i+=1
print(ans)

Solution (Python):
s = input()
d = []
i = 0
while i < len(s)-1:
    if s[i] == 'B' and s[i+1] == 'C':
        d.append('D')
        i += 2
    else:
        d.append(s[i])
        i += 1
ans = 0
x = 0
for i in range(len(d)):
    if d[i] == 'A':
        x += 1
    elif d[i] == 'D':
        ans += x
    else:
        x = 0
print(ans)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	
	
	
	s=input()
	pre='C'
	ret = 0
	a_num=0
	for c in s:
		d = pre + c
		if d == 'AA':
			a_num += 1
		elif d == 'BA':
			a_num=1
		elif d == 'CA':
			a_num += 1
		elif d == 'AB':
			pass
		elif d== 'BB':
			a_num = 0
		elif d == 'CB':
			pass
		elif d == 'AC':
			a_num = 0
		elif d == 'BC':
			ret += a_num
		else:
			a_num = 0
		
		pre = c
	return ret
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
S = input()

A = []

ok = 1
ans = 0
cnt = 0
for i in range(len(S)):
    if ok == 1 and i < len(S)-1 and S[i] == 'B' and S[i+1] == 'C':
        A.append('B')
        ans += cnt
    elif S[i] == 'A':
        A.append('A')
        cnt += 1
        ok = 1
    elif ok == 1 and i > 0 and S[i-1] == 'B' and S[i] == 'C':
        continue
    else:
        A = []
        cnt = 0
        ok = 0

print(ans)

Solution (Python):
s = str(input())

ans, cnt, i = 0, 0, 0
while i < len(s)-1:
  if s[i] == 'A':
    cnt += 1
    i += 1
  else:
    if s[i:i+2] == 'BC':
      ans += cnt
      i += 2
    else:
      cnt = 0
      i += 1
print(ans)

Solution (Python):
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

s = input()
n = len(s)
ans = 0
p = 0
cnt_a = 0
while True:
    while p<n and s[p] == 'A':
        cnt_a += 1
        p += 1
    
    while p<n-1 and s[p] == 'B' and s[p+1] == 'C':
        ans += cnt_a
        p+=2
    while p<n and s[p] == 'C':
        p+=1
        cnt_a = 0
    while p<n and s[p] == 'B':
        p+=1
        cnt_a=0
    
    if p>=n:
        break
print(ans)

Solution (Python):
a = list(input())
ans = 0
i = 0

a_count = 0  


while i < len(a)-1:
    if a[i] == "A":
        count = "A"
        a_count += 1
    elif a[i]+a[i+1] == "BC":
        count = "BC"
        ans += a_count
        i += 1
    else:
        count = "VBNM"
        a_count = 0
    
    i += 1

print(ans)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)









INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    S = input()
    SS = []
    dic = {'A': -1, 'B' : -2, 'C' : -3}
    chain = False
    skip = False
    for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    
    ans = 0
    BCbox = 0
    for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
    print(ans)



if __name__ == "__main__":
    run()

Solution (Python):
s=input()+"DDD"
n=len(s)-3
i=0
ac=0
c=0
while i<n:
  if s[i]=="A":
    ac+=1
    i+=1
  elif s[i:i+2]=="BC":
    c+=ac
    i+=2
  else:
    ac=0
    i+=1
print(c)

Solution (Python):
a=input()
a=a.replace("BC","X")
a=a[::-1]
X_c=0
ans=0
for i in range(len(a)):
   if a[i]=="X":
      X_c+=1
   elif a[i]=="A":
      ans+=X_c
   else:
      X_c=0
print(ans)

Solution (Python):
S = input()
cnt = 0
ans = 0
S = S.replace("BC","X")
S += "."
for s in S:
    if s == "X":
        ans += cnt
    elif s == "A":
        cnt += 1
    else:
        cnt = 0
print(ans)

Solution (Python):
s = list(input())[::-1]+["L"]
n = len(s)

ans = 0
count = 0
now = 0
while now < n-1:
    if s[now] == "C" and s[now+1] == "B":
        count += 1
        now += 2
    elif s[now] == "A":
        if count > 0:
            ans += count
        else:
            count = 0
        now += 1
    else:
        count = 0
        now += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))



def main():
	s=RD()[::-1]+"DDDDD"

	i=0
	cnt=0
	ans=0

	

	while i<=len(s)-3:
		if s[i:i+2]=="CB":
			cnt+=1
			i+=2
		elif s[i]=="A":
			ans+=cnt
			i+=1
		else:
			cnt=0
			i+=1
	print(ans)





if __name__ == "__main__":
	main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
ind = n-1
cnt = 0
res = 0
f = False
while ind >= 0:
    if ind-1 >= 0 and (s[ind-1],s[ind]) == ('B','C'):
        f = True
        cnt += 1
        ind -= 2
    elif f and s[ind] == 'A':
        res += cnt
        ind -= 1
    else:
        f = False
        cnt = 0
        ind -= 1
print(res)

Solution (Python):
s = input().replace('BC', 'D')
s = s.replace('B', 'C')
l = [x for x in s.split(sep='C') if x != '']
ans = 0
for subs in l:
    numA = 0
    for c in subs:
        if c == 'A':
            numA += 1
        elif c == 'D':
            ans += numA

print(ans)

Solution (Python):
s = input()
s = s.replace('BC','D')
a_cnt = 0
before_s = 'A'
ans = 0
for i in range(len(s)):

    if s[i] == 'A':
        a_cnt += 1
        before_s = s[i]
    elif (s[i]=='D'):
        ans +=a_cnt
        before_s = 'A'
    else:
        a_cnt = 0
        before_s = s[i]

print(ans)

Solution (Python):
s = input()

tmp = ""
cnt = 0
ans = 0
flag = False  
for i in range(0, len(s) - 1):
    if flag:
        flag = False
        continue
    if s[i] == "A":
        cnt += 1
    elif s[i] + s[i + 1] == "BC":
        ans += cnt
        flag = True
    else:
        cnt = 0

print(ans)

Solution (Python):
S = input()
S = S.replace("BC", "D")
cur = 0
ans = 0
for c in S:
    if c == "A":
        cur += 1
    elif c == "D":
        ans += cur
    else:
        cur = 0
print(ans)

Solution (Python):
class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.k_init = 2 ** (self.n - 1).bit_length()

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i


def get_invnum(li):
    n = len(li)
    t = FenwickTree(2)
    res = 0
    for i in range(n):
        if li[i] == "A":
            t.add(2, 1)
        else:
            res += t.sum(2)
    return res


S = input()
S = list(S.replace("BC", "D"))
N = len(S)
li = []
ans = 0
for c in S + ["B"]:
    if c not in ("A", "D"):
        ans += get_invnum(li)
        li = []
    else:
        li.append(c)
print(ans)

Solution (Python):
s = input()

aaa = 0
ans = 0
i = 0
while i < len(s) - 1:
    if s[i] == 'A':
        aaa += 1
    elif s[i:i+2] == 'BC':
        ans += aaa
        i += 1
    else:
        aaa = 0
    i += 1
print(ans)

Solution (Python):
s = input()
s = s.replace('BC','x')

a_flag = False
ans = 0
last_a = 0
for si in s:
    if si == 'A':
        a_flag = True
        last_a += 1
    elif si == 'x' and a_flag:
        ans += last_a
    else:
        a_flag = False
        last_a = 0

print(ans)

Solution (Python):
s = input()
s = s.replace('BC','x')

a_flag = False
ans = 0
last_a = 0
for si in s:
    if si == 'A':
        a_flag = True
        last_a += 1
    elif si == 'x' and a_flag:
        
        ans += last_a
    else:
        a_flag = False
        last_a = 0

print(ans)

Solution (Python):
s = str(input())
s = s.replace('BC', 'D')

S = []
temp = []
for c in s:
    if c == 'A' or c == 'D':
        temp.append(c)
    else:
        if temp:
            S.append(temp)
            temp = []
else:
    if temp:
        S.append(temp)

ans = 0
for s in S:
    cnt = 0
    for j in range(len(s)):
        if s[j] == 'A':
            cnt += 1
        else:
            ans += cnt
print(ans)

Solution (Python):
s = input()
s = s.replace("BC", "X")


cnt = 0
ans = []
for i in range(len(s)):
    if s[i] == "A": cnt += 1
    elif s[i] == "X": ans.append(cnt)
    else: cnt = 0
print(sum(ans))

Solution (Python):
s = input().replace("BC","D")
ans = 0
c = 0
for e in s:
    if e == "A":
        c += 1
    elif e == "D":
        ans += c
    else:
        c = 0
print(ans)

Solution (Python):
s = input()
s = s.replace('BC', 'D')
ans = []
tmp = 0
for i in reversed(range(len(s))):
    if s[i] == 'D':
        tmp += 1
    elif s[i] == 'A':
        ans.append(tmp)
    else:
        tmp = 0

print(sum(ans))

Solution (Python):
import sys
input = sys.stdin.readline

s = input()[:-1]
A = 0
ans = 0
i = 0

while i<len(s):
    if s[i]=='A':
        A += 1
        i += 1
    else:
        if i+1<len(s) and s[i:i+2]=='BC':
            ans += A
            i += 2
        else:
            A = 0
            i += 1

print(ans)

Solution (Python):
S = input()
news = S.replace('BC', 'D')

ans, cnt = 0, 0
for s in news:
    if s == 'A':
        cnt += 1
    elif s == 'D':
        ans += cnt
    else:
        cnt = 0

print(ans)

Solution (Python):
S = input()
S = S.replace('BC', 'D')
S = S.replace('B', 'C')
S = S.split('C')
ans = 0

def count_inv(s):
  res = num = 0
  for si in s:
    if si == 'A':
      num += 1
    else:
      res += num
  return res


for s in S:
  ans += count_inv(s)
  
print(ans)

Solution (Python):
S = input()
N = len(S)
ans = num_a = 0

pre_is_a = True
i = 0
while i < N:
    s = S[i]
    if s == 'A':
        pre_is_a = True
        num_a += 1
    elif s == 'B' and pre_is_a:
        num_bc = 0
        flag = True
        for j in range(i, N-1, 2):
            if S[j:j+2] == 'BC':
                num_bc += 1
            else:
                flag = False
                break
        if num_bc:
            ans += num_a * num_bc
            if flag:
                i = N
            else:
                i = j - 1
        else:
            pre_a = False
            num_a = 0
    else:
        pre_a = False
        num_a = 0

    i += 1

print(ans)

Solution (Python):
s=input().replace("BC","D")
count=0
ans=0
for i in range(len(s)):
    if s[i]=="A":
        count+=1
    elif s[i]=="D":
        ans+=count
    else:
        count=0
print(ans)

Solution (Python):
s=input().replace("BC","D")
s=s+"0"
count=0
ans=0
for i in range(len(s)):
    if s[i]=="A":
        count+=1
    elif s[i]=="D":
        ans+=count
    else:
        count=0
print(ans)

Solution (Python):
s=input()
n=len(s)
i=0
cnt=0
ans=0
while i<n:
  if s[i]=='A':
    i+=1
    cnt+=1
    while s[i:i+2]=='BC':
      ans+=cnt
      i+=2
  else:
    cnt=0
    i+=1
print(ans)

Solution (Python):




def main():
	s = input()
	cnt = 0
	prev =0
	ans = 0
	i = len(s)-1
	while i>=0:
		if s[i]=='C' and s[i-1]=='B':
			cnt = cnt+1
			i = i-2
		else:
			if s[i]=='A':
				ans = ans+cnt
			else:
				cnt = 0
			i = i-1
	print(ans)
if __name__=="__main__":
	main()

Solution (Python):




def main():
	s = input()
	cnt = 0
	prev =0
	ans = 0
	i = len(s)-1
	while i>=0:
		if s[i]=='C' and s[i-1]=='B':
			cnt = cnt+1
			i = i-2
		else:
			if s[i]=='A':
				ans = ans+cnt
			else:
				cnt = 0
			i = i-1
	print(ans)
if __name__=="__main__":
	main()

Solution (Python):

def main():
	s = input()
	cnt = 0
	prev =0
	ans = 0
	i = len(s)-1
	while i>=0:
		if s[i]=='C' and s[i-1]=='B':
			cnt = cnt+1
			i = i-2
		else:
			if s[i]=='A':
				ans = ans+cnt
			else:
				cnt = 0
			i = i-1
	print(ans)
if __name__=="__main__":
	main()

Solution (Python):
s=list(input())
s.append("D")
S=[]
i=0
while i<len(s):
  if s[i]=="A":
    S.append(1)
    i=i+1
  elif s[i]=="B":
    if s[i+1]=="C":
      S.append(2)
      i=i+2
    else:
      S.append(3)
      i=i+1
  else:
    S.append(3)
    i=i+1
ans=0
a=0
b=0
for i in range(len(S)):
  if S[i]==1:
    a=a+1
  elif S[i]==2:
    b=b+1
    ans=ans+a
  else:
    a=0
    b=0
print(ans)

Solution (Python):
S=input()

N=len(S)
if N<3:
    print(0)
    exit()
S=list(S)

As=0

BCs=0
ans=0
flag=False
safe=-1
for i in range(N-2):
    if "".join(S[i:i+3])=="ABC":
        ans+=1
        ans+=As


        S[i]="B"
        S[i+1]="C"
        S[i+2]="A"
        safe=i+1

    elif S[i]=="A":
        As+=1
    else:
        if i!=safe:
            As=0
    

print(ans)

Solution (Python):
S = input()
S=S.replace("BC", "D")

ca = 0

T = []

tt = ""
for i in range(len(S)):
    if S[i] == 'A':
        tt += S[i]

    elif S[i] == 'B' or S[i] == 'C':
        
        if tt != "":
            T.append(tt)
            tt = ""
    
    elif S[i] == 'D':
        tt += S[i]

if tt != "":
    T.append(tt)
    tt = ""


ans = 0
for seq in T:
    ca = 0
    for c in seq:
        if c == 'A':
            ca += 1
        else:
            ans += ca

print(ans)

Solution (Python):
s = input()


s = s.replace('BC', 'D')


ans = 0
cntA = 0
for i in range(len(s)):
    if s[i] == 'A':
        cntA += 1
    elif s[i] == 'D':
        ans += cntA
    
    else:
        cntA = 0

print(ans)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



s = input()
s = s.replace('BC', 'D')
s_list = s.split("B")
x = []
for e in s_list:
    x += e.split("C")

ans = 0
for e in x:
    cnt_d = 0
    now = 0
    for c in e[::-1]:
        if c == 'D':
            cnt_d += 1
        if c == 'A':
            now += cnt_d
    ans += now
print(ans)

Solution (Python):
def agc034_b():
    s = str(input())
    n = len(s)
    if n < 3: return print(0)

    r = s[::-1]
    cb = 0
    ans = 0
    for i in range(1, n):
        if r[i] == 'A':
            if r[i-1] == 'C': cb = 0
            else: ans += cb
        elif r[i] == 'B':
            if r[i-1] == 'C': cb += 1
            else: cb = 0
        else:
            if r[i-1] == 'C': cb = 0
            else: continue
    print(ans)

if __name__ == '__main__':
    agc034_b()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    lS = list(S)
    acnt = 0
    ans = 0
    for i in range(len(S) - 2):
        if lS[i] == "A":
            acnt += 1
        else:
            acnt = 0

        if lS[i] == "A" and lS[i + 1] == "B" and lS[i + 2] == "C":
            ans += acnt
            lS[i + 2] = "A"
            if acnt > 1:
                lS[i + 1] = "A"
                acnt -= 2

    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
s = input()
s = s.replace('BC', 'D')
ans = 0
cntA = 0
for i in range(len(s)):
    if s[i] == 'A':
        cntA += 1
    elif s[i] == 'D':
        ans += cntA
    else:
        cntA = 0

print(ans)

Solution (Python):
def main():
    S = input()
    
    
    
    
    
    
    T = list()
    for ch in S:
        if len(T) > 0 and T[-1] == 'B' and ch == 'C':
            T[-1] = 'D'
            continue
        T.append(ch)
    T.reverse()
    ans, cnt_d = 0, 0
    for ch in T:
        if ch == 'A':
            ans += cnt_d
        elif ch in ['B', 'C']:
            cnt_d = 0
        else:  
            cnt_d += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s=input()
s=s.replace('BC','.')
s=s.replace('B','/')
s=s.replace('C','/')
sl = s.split('/')
cnt =0
for si in sl:
    incre = 0
    for ci in si:
        if ci == 'A':
            incre +=1
        if ci == '.':
            cnt += incre
print(cnt)

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=input()
    S=S.replace("BC","D")
    S+="Z"
    N=len(S)
    ans=0
    cnta=0

    
    for i in range(N):
        if S[i]=="D":
            ans+=cnta
        elif S[i]=="A":
            cnta+=1
        else:
            cnta=0
                
    print(ans)
            

main()

Solution (Python):
s=input()
s=s.replace('BC','.')
s=s.replace('B','/')
s=s.replace('C','/')
sl = s.split('/')
cnt =0
for si in sl:
    incre = 0
    for ci in si:
        if ci == 'A':
            incre +=1
        if ci == '.':
            cnt += incre
print(cnt)

Solution (Python):
s=list(input())
n=len(s)
S=[]
t=0
while t<n-1:
    if s[t]=='B' and s[t+1]=='C':
        S.append('R')
        t+=1
    else:
        S.append(s[t])
    t+=1
if t==n-1:
    S.append(s[t])
m=len(S)
amount=0
bc=0
a=0
for i in range(m):
    if S[i]=='A':
        a += 1
    elif S[i]=='R':
        amount += a
        bc=1
    else:
        a=0
        bc=0
print(amount)

Solution (Python):
s = input()
a = 0
ans = 0
n = len(s)
i = 0
while(i<n):
  if s[i] == "A":
    a += 1
  elif s[i] == "B" and i+1<n and s[i+1] == "C":
    ans += a
    i += 1
  else:
    a = 0
  i += 1
print(ans)

Solution (Python):

        
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    s = s.replace('BC', 'D')
    n = len(s)
    i = 0
    ans = 0
    while i < n:
        while i < n and (s[i] == 'B' or s[i]=='C'):
            i += 1
        st = i
        cnt = 0
        while i < n and (s[i] == 'A' or s[i]=='D'):
            if s[i] == 'A':
                cnt += 1
            i += 1
        ed = i
        for j in range(st, ed):
            if s[j] == 'A':
                cnt -= 1
                ans +=ed-j-cnt-1
    print(ans)

    
    


                
if __name__ == '__main__':
    main()

Solution (Python):
s = list(input())
n = len(s)
ans = 0
c = 0
i = 0
while i < n-1:
    if s[i] == "B" and s[i+1] == "C":
        ans += c
        i += 1
    elif s[i] == "A":
        c += 1
    else:
        c = 0
    i += 1
print(ans)

Solution (Python):

s = input()
i, ans, total = 0, 0, 0

while i < len(s) - 1:
    if s[i: i + 2] == "BC":
        ans += total 
        i += 2
    elif s[i] == "A":
        total += 1
        i += 1
    else:
        total = 0
        i += 1

print(ans)

Solution (Python):


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):  
        return str(list(self))

    def sum(self, 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):
        
        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"))))

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    t = s.replace("BC", "X")

    ans = 0
    cnt = 0

    for char in t[::-1]:
        if char == "X":
            cnt += 1
        elif char == "A":
            ans += cnt
        else:
            cnt = 0

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    
    
    ans = 0
    len_s = len(s)
    cnt = 0
    i = 0
    while i < len_s:
        if s[i] == 'A':
            cnt += 1
            i += 1
        elif i + 1 < len_s and s[i] == 'B' and s[i+1] == 'C':
            ans += cnt
            i += 2
        else:
            cnt = 0
            i += 1
            
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    
    
    ans = 0
    len_s = len(s)
    cnt = 0
    i = 0
    while i < len_s:
        
        if s[i] == 'A':
            cnt += 1
            i += 1
        elif i + 1 < len_s and s[i] == 'B' and s[i+1] == 'C':
            ans += cnt
            i += 2
        else:
            cnt = 0
            i += 1
            
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
s = input().replace('BC','a')

ans, cnta = 0, 0
for i in range(len(s)):
    if s[i] == 'A':
        cnta += 1
    elif s[i] == 'a':
        ans += cnta
    else:
        cnta = 0
print(ans)

Solution (Python):
s = input()

ans, cnta = 0, 0
for i in range(len(s)):
    if s[i] == 'A':
        cnta += 1
    elif s[i:i + 2] == 'BC':
        ans += cnta
    elif s[i - 1:i + 1] != 'BC':
        cnta = 0
print(ans)

Solution (Python):
s = list(input())
li = []
n = len(s)
ans = 0
b = False
for i in range(n-1):
    if b:
        b = False
        continue
    if s[i] + s[i+1] == 'BC':
        li.append('D')
        b = True
    if s[i] == 'B' and s[i+1] != 'C':
        li.append('E')
    if s[i] == 'C':
        li.append('E')
    if s[i] == 'A':
        li.append('A')
cnt = 0
for i in range(len(li)):
    if li[i] == 'A':
        cnt += 1
    elif li[i] == 'E':
        cnt = 0
    else:
        ans += cnt
print(ans)

Solution (Python):
s = list(input())
li = []
n = len(s)
ans = 0
b = False
for i in range(n-1):
    if b:
        b = False
        continue
    if s[i] + s[i+1] == 'BC':
        li.append('D')
        b = True
    if s[i] == 'B' and s[i+1] != 'C':
        li.append('E')
    if s[i] == 'C':
        li.append('E')
    if s[i] == 'A':
        li.append('A')
cnt = 0
for i in range(len(li)):
    if li[i] == 'A':
        cnt += 1
    elif li[i] == 'E':
        cnt = 0
    else:
        ans += cnt
print(ans)

Solution (Python):
S = input()

rlt = 0
b = ''
tA = 0
A = 0
BC = 0
for s in S:
  if s == 'A':
    if b == 'A':
      tA += 1
    elif b == 'B':
      rlt += A*BC
      tA = 1
      A = 0
      BC = 0
    else:
      rlt += A*BC
      tA = A + 1
      A = 0
      BC = 0
  elif s == 'B':
    if b == 'B':
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  elif s == 'C':
    if b == 'B':
      A += tA
      tA = 0
      BC += 1
    else:
      rlt += A*BC
      tA = 0
      A = 0
      BC = 0
  b = s

rlt += A*BC
  
print(rlt)