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().strip().replace('BC', 'D')
n = len(s)

count = 0
a_count = 0
for i in range(n):
  if s[i] == 'A':
    a_count += 1
  elif a_count > 0 and s[i] == 'D':
    count += a_count
  else:
    a_count = 0

print(count)

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

Solution (Python):

import os
import time
import re
import math

def main():
    s=input().replace("BC","D")
    max=0
    acount=0
    for a in range(len(s)):
        if s[a]=='D':
            max+=acount
        elif s[a]=='A':
            acount+=1
        else:
            acount=0
    print(max)



start=time.time();
main()

Solution (Python):

import os
import time
import re
import math

def main():
    s=input().replace("BC","D")
    max=0
    acount=0
    for a in s:
        if a=='D':
            max+=acount
        elif a=='A':
            acount+=1
        else:
            acount=0
    print(max)
start=time.time();
main()

Solution (Python):
s=input()
ans=0
cnt=0
flag=0
for i in range(len(s)-1,-1,-1):
  if flag==0:
    if s[i]=='C':
      flag=1
    elif s[i]=='A':
      ans+=cnt
    elif s[i]=='B':
      cnt=0
  elif flag==1:
    if s[i]=='B':
      flag=0
      cnt+=1
    elif s[i]=='C':
      cnt=0
    elif s[i]=='A':
      flag=0
      cnt=0
print(ans)

Solution (Python):
s = input()
s = s.replace("BC","D")
count_Sum = 0
countA = 0
countD = 0

for i in range(len(s)):
    if s[i] == "A" and countD == 0:
        countA += 1
    elif s[i] == "D":
        countD += 1
        if i+1 == len(s):
            count_Sum += countA*countD
    else:
        count_Sum += countA*countD
        if s[i] == "B" or s[i] =="C":
            countA = 0
            countD = 0
        else:
            countA += 1
            countD = 0
print(count_Sum)

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

ans = 0
count_a = 0
for i in range(length):
  c = S[i]

  if c == 'A':
    count_a += 1
  elif c == 'D':
    ans += count_a
  else:
    count_a = 0

print(ans)

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

Solution (Python):



def count(s):
	i = 0
	a_cnt = 0
	cnt = 0
	while i < len(s):
		if s[i] == 'A':
			a_cnt += 1
		if s[i] =='D':
			cnt += a_cnt

		i += 1

	return cnt



originalS = raw_input()
originalS = originalS.replace('BC', 'D')
originalS = 'B'+originalS+'B'	


idx = []
i = 0

while i < len(originalS):
	if (originalS[i] == 'B')|(originalS[i] == 'C'):
		idx.append(i)
	i += 1


Substr = []

i = 0
while i < len(idx)-1:
	if idx[i+1]-idx[i]!=1:
		Substr.append(originalS[idx[i]+1:idx[i+1]])

	i += 1

ans = 0
for c in Substr:
	ans += count(c)

print ans

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

res = 0
num = 0
for i in s:
    if i == "B" or i == "C":
        num = 0
    elif i == "A":
        num += 1
    else:
        res += num

print(res)

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

def main():
    res = 0
    num = 0
    for i in s:
        if i == "B" or i == "C":
            num = 0
        elif i == "A":
            num += 1
        else:
            res += num
    
    print(res)



if __name__ == "__main__":
    main()

Solution (Python):
s = input()

count = 0
counta = 0
for i in range(len(s)):
    if s[i] == "A":
        if s[i-1] != "B" or i == 0:
            counta += 1
        else:
            counta = 1
    elif s[i] == "B":
        if s[i-1] == "B":
            counta = 0
    else:
        if s[i-1] == "B":
            count += counta
        else:
            counta = 0
print(count)

Solution (Python):
from sys import stdin

def main():
    S = input()

    S_ = S.replace('BC', 'D')
    ans, cnt = 0, 0
    for s in S_[::-1]:
        if s == 'D':
            cnt += 1
        elif s == 'A':
            ans += cnt
        else:
            cnt = 0
    print(ans)

input = lambda: stdin.readline().rstrip()
main()

Solution (Python):
s = input()

count = 0
ans = 0

ss = s.replace('BC','X')

flag = 0

for i in ss:
    if i == 'A':
        flag += 1
    elif i == 'X':
        ans += flag
    else:
        flag = 0

print(ans)

Solution (Python):
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]

    for a in arr:
        tmp = 0
        for i in a:
            i = int(i)
            tmp += i
            if i is 0:
                cnt += tmp

    return cnt


if __name__ == '__main__':
    print(main())

Solution (Python):
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    s = input()
    cnt = 0
    s = s.replace('A', '1').replace('BC', '0')
    arr = re.split('[A-C]', s)
    arr = [list(x) for x in arr]
    flag = True
    while flag:
        flag = False
        for a in arr:
            tmp = 0
            for i in a:
                i = int(i)
                tmp += i
                if i is 0:
                    cnt += tmp

    return cnt


if __name__ == '__main__':
    print(main())

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

a = 0
cnt = 0
for x in s:
    if x == 'A':
        a += 1
    elif x == 'D':
        cnt += a
    else:
        a = 0

print(cnt)

Solution (Python):
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV=10**9+7


ESP_C = "$"
S=input()

def main():
    nS = S.replace("BC",ESP_C)
    ans =0
    a_buf =0
    for idx,c in enumerate(nS):
        if c == "A":
            a_buf+=1
        elif c == ESP_C:
            ans+=a_buf
        else:
            a_buf =0
    return ans

print(main())

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

i=0
j=0
ans=0
z=[]
while i!=len(s)-1:
    try:
        if s[i]=="B" and s[i+1]=="C":
            z.append(1)
            i=i+2

        else:
            if s[i]=="A":
                z.append(2)
                i=i+1

            else:
                z.append(0)
                i=i+1

    except:
      break

ans=0
i=0
r1=0





while i!=len(z):
    if z[i]==2:
         r1=r1+1

    elif z[i]==1:
        ans=ans+r1

    else:
        r1 = 0


    i=i+1
print(ans)

Solution (Python):
S = input()


ans = 0
i = 0
running_A_count = 0
while i + 1 < len(S):
    if S[i] == "A":
        running_A_count += 1
    elif S[i] == "B" and S[i+1] == "C":
        ans += running_A_count
        i += 1
    else:
        running_A_count = 0
    
    i += 1






print(ans)

Solution (Python):
import re
S = input()
N1 = S.replace('A','0').replace('BC','1')
S_li = re.split('B|C',N1)
 
count = 0
for l in S_li:
    a = sum([i for i,x in enumerate(l) if '1' in x])
    su=sum([x for x in range(l.count('1'))])
    count += (a-su)
print(str(count))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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

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

Solution (Python):
s = input()
 
ans = 0
s = s.replace("BC","D")
cnt_A = 0
 

for i in s:
    if i == "A":
        cnt_A += 1
    elif i == "D":
        ans += cnt_A
    else:
        cnt_A = 0

print(ans)

Solution (Python):
import re

s = input()
s = re.sub('BC', 'D', s)

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

print(ans)

Solution (Python):
import re

s = input()
s = s.replace('BC', 'D')
ss = [c for c in re.split('[BC]', s) if c != '']

sum = 0
for s in ss:
  na = 0
  for c in s:
    if c == 'A':
      na += 1
    else:
      sum += na

print(sum)

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

A, ans = 0, 0

for i in s2:
    if i == "A":
        A += 1
    elif i == "D":
        ans += A
    else:
        A = 0

print(ans)

Solution (Python):
def f(ss):
  n=len(ss)
  ct,res=0,0
  for i in range(n):
    if ss[i]=="x":
      ct+=1
    else:
      res+=ct
  return res
s=input()
s=s.replace("BC","y")
s=s.replace("A","x")
s+="z"
ans=0
chk=""
for i in range(len(s)):
  if s[i]=="x" or s[i]=="y":
    chk+=s[i]
  else:
    ans+=f(chk)
    chk=""
print(ans)

Solution (Python):
s=raw_input()
l=len(s)

i=0
cnt=0
ans=0
while i<l:
	x=s[i]
	if x=="A":
		i+=1
		cnt+=1
	elif i+1<l and s[i]=="B" and s[i+1]=="C":
		i+=2
		ans+=cnt
	else:
		i+=1
		cnt=0


print ans

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


s = input()
if not ('ABC' in s):
  print(0)
  exit()

from collections import deque
S = deque(maxlen=200000)
tmp = 'C'
for ss in s:
  if tmp == 'B' and ss == 'C':
    S.pop()
    S.append('D')
    tmp = 'C'
  elif ss == 'C':
    S.append('B')
    tmp = 'C'
  else:
    S.append(ss)
    tmp = ss

ans = 0
ihavea = 0

Acnt = 0
while 1:
  try:
    tmp = S.popleft()
  except:
    print(ans)
    exit()
  if tmp=='B':
    ihavea = 0
    Acnt = 0
    continue
  if ihavea == 0 and tmp=='A':
    ihavea = 1
    Acnt += 1
    continue
  if ihavea == 1 and tmp=='A':
    ihavea = 1
    Acnt += 1
    continue
  if ihavea == 1 and tmp=='D':
    ihavea = 1
    ans += Acnt
    
    continue

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

for c in s:
    if c == 'A':
        cnt += 1
    elif c == 'D':
        ans += cnt
    else:
        cnt = 0
print(ans)

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

Solution (Python):
s = input()
s = s.replace("BC","X")
ans = []
c = 0

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

Solution (Python):

import sys


def solve(s: str):
    
    s = s.replace('BC', 'X')

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

    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):
a = input()
b = []
count = 0
a = a.replace('BC','D')
for i in range(1,len(a)+1):
    if a[-i] == 'D':
        count += 1
    elif a[-i] == 'A':
        b.append(count)
    else:
        count = 0
print(sum(b))

Solution (Python):
s = input()

N = len(s)

i = 0
result = 0
count_a = 0
count_bc = 0

while i < N-2:
    if s[i] == 'A':
        while s[i] == 'A' and i < N-2:
            count_a += 1
            i += 1
        
        if i >= N-1:
            break
                        
        while s[i] == 'B' and s[i+1] == 'C':
            count_bc += 1
            i += 2
            if i >= N-1:
                break
        
        result += count_a * count_bc

        if i >= N-1:
            break
        
        if count_bc > 0 and s[i] == 'A':
            count_a = count_a
        else:
            count_a = 0
        
        count_bc = 0
                    
    else:
        i += 1
        
print(result)

Solution (Python):
s=input()
arr=[]
i=0
while i<(len(s)):
    if s[i]=='A':
        arr.append('A')
        i+=1
        continue
    else:
        if (i+1)<len(s):
            if s[i:i+2]=='BC':
                arr.append('D')
                i+=2
                continue
            else:
                arr.append(s[i])
                i+=1
                continue
        else:
            arr.append(s[i])
            i+=1
temp=''.join(arr)
a=False
count=0
ans=0

for i in range(len(temp)):
    if not a:
        if temp[i]=='A':
            count+=1
            a=True
    else:
        if temp[i]=='D':
            ans+=count
        elif temp[i]=='A':
            count+=1 
        else:
            
            
            count=0 
            a=False
    
print(ans)

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

s = input()
s = s.replace('BC', 'D')
s = re.split('[BC]', s)
res = 0

for kk in s:
  if not kk:
    continue
  d = 0
  for a in kk[::-1]:
    if a == 'D':
      d += 1
    else:
      res += d
    
print(res)

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

s = input()
s = s[::-1]
ans = 0
a = -1
s = (s.replace('CB', 'D').replace('C', '\t').replace('B', '\t')).split()
for i in range(len(s)):
    for j in range(s[i].count('A')):
        a = s[i].find('A',a+1)
        ans += a-j
    a = -1
print(ans)

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


ans = 0
cnt_a = 0
for i in range(len(s)):
    if s[i] in ["B", "C"]:
        cnt_a = 0
    elif s[i] == "A":
        cnt_a += 1
    elif s[i] == "D":
        ans += cnt_a

print(ans)

Solution (Python):
S = input()
N = len(S)
ans = 0
X = [0] * (N+2)
for i in range(N)[::-1]:
    if S[i:i+2] == "BC":
        X[i] = X[i+2] + 1
    elif S[i] == "A":
        X[i] = X[i+1]
        ans += X[i]
    else:
        X[i] = 0

print(ans)

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

cnt = 0
num_a = 0
for i in range(len(s)):
    if s[i] in ["B", "C"]:
        num_a = 0
    elif s[i] == "A":
        num_a += 1
    elif s[i] == "D":
        cnt += num_a

print(cnt)

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

t = []

i = 0
while i < len(s) - 1:
    if s[i] == 'A':
        t.append('A')
        i += 1
    elif s[i] == 'B':
        if s[i+1] == 'C':
            t.append('D')
            i += 2
        else:
            t.append('B')
            i += 1
    else:
        t.append('C')
        i += 1

mode = 0
ans = 0
count = 0

for x in t:
    if mode == 0:
        if x == 'A':
            count = 1
            mode = 1
    else:
        if x == 'A':
            count += 1
        elif x == 'D':
            ans += count
        else:
            mode = 0

print(ans)

Solution (Python):
s=input()
t=''
skip=False
for i in range(len(s)-1):
    if skip:
        skip=False
        continue
    if s[i:i+2]=='BC':
        t+='D'
        skip=True
    else:
        t+=s[i]

ans,cnt=0,0
for i in range(len(t)):
    if t[i]=='A':
        cnt+=1
    if t[i] in ['B','C']:
        cnt=0
    if t[i]=='D':
        ans+=cnt
print(ans)

Solution (Python):
S = input()
ans = 0
A = 0
BC = 0
prv = 0
if S[0] == 'A':
    A += 1
    prv = 'A'
else:
    prv = S[0]
for i in S[1:]:
    if prv == 'A':
        if i == 'A':
            A += 1
        elif i == 'B':
            prv = 'B'
        else:
            ans += A*BC
            A = 0
            BC = 0
            prv = 'C'
    elif prv == 'B':
        if i == 'A':
            ans += A*BC
            A = 1
            BC = 0
            prv = 'A'
        elif i == 'B':
            ans += A*BC
            A = 0
            BC = 0
        else:
            BC += 1
            prv = 'C'
    else:
        if i == 'A':
            ans += A*BC
            A += 1
            BC = 0
            prv = 'A'
        elif i == 'B':
            prv = 'B'
        else:
            ans += A*BC
            A = 0
            BC = 0
ans += A*BC
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
S = S.replace("BC", "X")  
S = S.replace("B", "C")  

L = S.split("C")
ans = 0

for l in L:
    X_num = l.count('X')
    for c in l:
        if c == "X":
            X_num -= 1
        else:
            ans += X_num
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
S = S.replace("BC", "X")
S = S.replace("B", "C")

L = S.split("C")
ans = 0
for l in L:
    X_num = l.count('X')
    for c in l:
        if c == "X":
            X_num -= 1
        else:
            ans += X_num
print(ans)

Solution (Python):
s = input()
num_a = 0
num_ab = 0
val = 0
for i in range(len(s)):
    if s[i] == 'A':
        num_a += 1
    elif s[i] == 'B':
        num_ab = num_a
        num_a = 0
    else:
        if num_a == 0:
            val += num_ab
            num_a = num_ab
            num_ab = 0
        else:
            num_a = 0
            num_ab = 0
print(val)

Solution (Python):
s = input()
s = s.replace('BC', 'D')
total = 0
cnt = 0
for it in s:
    if it == 'A':
        cnt+=1
    elif it=='D':
        total += cnt
    else:
        cnt = 0
print(total)

Solution (Python):
s = input()
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0
 
while i < len(s)-1:
    
    if s[i] == 'B' and s[i+1] == 'C':
        if inRange:
            total += (range_cnt - range_minus)
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == 'A':
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i+=1
    
print(total)

Solution (Python):
s = input()
total = 0
i = 0
inRange = False
range_start = 0
range_minus = 0
range_cnt = 0

while i < len(s)-1:
    
    if s[i] == 'B' and s[i+1] == 'C':
        if inRange:
            total += (range_cnt - range_minus)
            range_cnt += 1
            range_minus += 1
        i += 1
    elif s[i] == 'A':
        inRange = True
        range_cnt += 1
    else:
        inRange = False
        range_start = 0
        range_minus = 0
        range_cnt = 0
    i+=1
    
print(total)

Solution (Python):
s = input()

count = 0
pre = ''
movable = 0
for i in reversed(s):
    if pre == '':
        pre = i
    elif pre == 'CB' and i == 'A':
        count += movable
    elif pre == 'CB' and i == 'C':
        pre = 'C'    
    elif pre == 'C' and i == 'B':
        movable += 1
        pre = 'CB'
    else:
        movable = 0
        pre = i   
print(count)

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

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

ans = 0
cnt = 0

for s in S :
    if s == "A" :
        cnt += 1
    elif s == "D" :
        ans += cnt
    else :
        cnt = 0

print(ans)

Solution (Python):
def b():
    import re
    s = input()
    s = re.sub(r'BC', 'D', s)
    ls = range(len(s))
    ac, c = 0, 0
    for i in ls:
        if s[i] == 'A':
            ac += 1
        elif s[i] == 'D':
            c += ac
        else:
            ac = 0
    return c


ans = b()
print(ans)

Solution (Python):
def b():
    import re
    s = input()
    s = re.sub(r'BC', 'D', s)
    ls = range(len(s))
    ac, c = 0, 0
    for i in ls:
        if s[i] == 'A':
            ac += 1
        elif s[i] == 'D':
            c += ac
        else:
            ac = 0
    return c


ans = b()
print(ans)

Solution (Python):
S = input()

ans = 0
cnt = 0
flg = 0

for i in range(len(S)-1) :
    if S[i] == "A" :
        cnt += 1
    elif S[i]+S[i+1] == "BC" :
        ans += cnt
        flg = 1
    elif flg :
        flg = 0
    else :
        cnt = 0

print(ans)

Solution (Python):

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

a_num = 0
ans = 0
for c in s:
    if c == 'A':
        a_num += 1
    elif c == 'D':
        ans += a_num
    else:
        a_num = 0

print(ans)

Solution (Python):

s = input()

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

print(ans)

Solution (Python):

s = input()

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

print(ans)

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

Solution (Python):
a=b=0
for s in input().replace('BC','?'):b=s<'B'and(s>'?')+b;a+=b*(s<'A')
print(a)

Solution (Python):
a=b=0
for s in input().replace('BC','?'):b=s<'B'and(s>'?')+b;a+=b*(s<'A')
print(a)

Solution (Python):
a=b=0
for s in input().replace('BC','?'):b=(b+(s>'?'))*(s<'B');a+=b*(s<'A')
print(a)

Solution (Python):
import re

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

count = 0
count_a = 0
for string in s:
    if string == 'A':
        count_a += 1
    elif string == 'D':
        count += count_a
    else:
        count_a = 0

print(count)

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

cnt = 0
cnA = 0
i = 0
while i < len(s) - 1:
    
    if s[i:i + 2] == ["B", "C"]:
        cnt += cnA
        i += 1
    elif s[i] == "A":
        cnA += 1
    else:
        cnA = 0
    i += 1

print(cnt)

Solution (Python):
S = input()
l = len(S)
A = ""
k = 0
while k < l-1:
    if S[k:k+2] == "BC":
        A += "D"
        k += 2
    else:
        A += S[k]
        k += 1
S = A
S = S.replace("B","C")
L = list(S.split("C"))

def keisan(s):
    if len(s) == 0:
        return 0
    l = len(s)
    t = 1
    ret = 0
    for k in range(len(s)):
        if s[k] == "A":
            ret += l-k-t
            t += 1
    return ret

ans = 0
for s in L:
    ans += keisan(s)
print(ans)

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

ret = 0
i = 0
a = 0
bc = 0

while True :
    while i < len(s) and s[i] == 'A' :
        a += 1
        i += 1

    while i < len(s) - 1 and s[i:i+2] == ['B', 'C']  :
        bc += 1
        i += 2

    ret += a * bc

    bc = 0

    if i < len(s) and s[i] != 'A' :
        a = 0
        
    while i < len(s) and s[i] != 'A' :
        i += 1

    if i >= len(s) - 1 :
        break
    

print(ret)

Solution (Python):

s = input()

s = s.replace("BC", "*")

point = 0
charge = 0
for i in range(len(s) - 1, -1, -1):
    if s[i] == "*":
        charge += 1
    elif s[i] == "A":
        point += charge
    else:
        charge = 0

print(point)

Solution (Python):
s=input()
s=s.replace('BC','D')
s=list(s)
count=0
 
def change():
  global count
  flg=False
  acount=0
  for i in range(len(s)-1):
    if s[i]=='A' and s[i+1]=='D':
      s[i]='D'
      s[i+1]='A'
      count+=1
      flg=True
      count+=acount
    elif s[i]=='A':
      acount+=1
    else:
      acount=0
      
  return flg
      
change()
 
print(count)

Solution (Python):
def solve2():
    s = raw_input()
    s = s.replace('BC', 'X')
    ans = 0
    acc_A = 0
    for ele in s:
        if ele == 'A':
            acc_A += 1
        elif ele == 'X':
            ans += acc_A
        else:
            acc_A = 0
    print ans

if __name__ == '__main__':
    solve2()

Solution (Python):
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
  
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
def minus(n):
  return 128-n

s = input()
total = 0
new_s = s.replace("BC", "D")
new_s_list = list(new_s)
new_s_list.append("G")
tmp_start = 0
for i in range(len(new_s_list)):
  if new_s_list[i] in {'B', 'C', 'G'}:
    ppp = list(map(minus, map(ord, new_s_list[tmp_start:i])))
    bit = Bit(128)
    ans = 0
    for j, p in enumerate(ppp):
      bit.add(p, 1)
      ans += j + 1 - bit.sum(p)
    total += ans
    tmp_start = i+1

print(total)

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

Solution (Python):
from collections import Counter as D, defaultdict as dd
from math import factorial as ft, ceil as aron
from fractions import gcd as pg 
from bisect import insort as ins, bisect_left as bl, bisect_right as br
import sys


raw_input=sys.stdin.readline

f1=lambda : map(int,raw_input().split())
f2=lambda : map(int,list(raw_input()))
f3=lambda : int(raw_input())
f4=lambda : raw_input().rstrip()
def main():
	
	s=f4()
	n1=0
	ans=0
	i=0
	while i<len(s)-1:
		if s[i]=="A":
			n1+=1
		elif s[i:i+2]=="BC":
			ans+=n1
			i+=1
		else:
			n1=0
		i+=1
	print ans

if __name__ == '__main__':
	main()

Solution (Python):
S = input().replace('BC', 'X')
N = len(S)

ans = 0
tmp = 0
for i in range(N-1, -1, -1):
    if S[i] == 'A':
        ans += tmp
    elif S[i] == 'X':
        tmp += 1
    else:
        tmp = 0
print(ans)

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

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000)

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

s=input()
s=s.replace("BC","D")
acnt=0
dcnt=0
ans=0
for i in s[::-1]:
    if i=="D":
        ans+=acnt*dcnt
        acnt=0
        dcnt+=1
    elif i=="A":
        acnt+=1
    else:
        ans += acnt * dcnt
        acnt=0
        dcnt=0
ans+=acnt*dcnt
print(ans)

Solution (Python):

import re

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

ans = 0
num_a = 0
for char in s:
    if char == 'A':
        num_a += 1
    elif char == 'D':
        ans += num_a
    else:
        num_a = 0

print(ans)

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

a = 0 
ans = 0 

for i in t:
    if i == 'A':
        a += 1
    elif i == 'D':
        ans += a
    else:
        a = 0

print(ans)

Solution (Python):
S = input().replace("BC", "D")
acc = 0
ans = 0
for s in S:
  if s == "B" or s == "C":
    acc = 0
    continue
  if s == "A":
    acc += 1
  if s == "D":
    ans += acc
print(ans)

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

ans = 0
for s in S:
    temp = 0
    for c in s:
        if c == 'A':
            temp += 1
        else:
            ans += temp
print(ans)

Solution (Python):

from re import sub

raw_s = input()

s = sub("BC","D",raw_s)



ac = 0
ans = 0
for c in s:
    if c == 'A':
        ac += 1

    elif c == 'D':
        ans += ac
        
    else:
        ac = 0
        
print(ans)

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

print(answer)

Solution (Python):


import sys
import re

s= sys.stdin.readline().strip()
s= s.replace("BC","D")
s= re.sub("[BC]+"," ",s).split()

t= 0
for seg in s:
    a= 0
    for c in seg:
        if c=="A": a+=1
        elif c=="D": t+= a

print( t )

Solution (Python):
s = input()
s = s.replace("BC","D").replace("B","E").replace("C","E")
s = s.split("E")

def solve(s):
    ans = 0 ; tmp = 0
    for char in s:
        if char == "A": tmp += 1
        else: ans += tmp
    return ans

ans = 0
for ele in s: ans += solve(ele)
print(ans)

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()

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

print(ans)

Solution (Python):

import sys

def conv2num(c):
    if c == "A":
        return 1
    elif c == "D":
        return 2
    elif c == "B":
        return 3
    else:
        return 4

def solve(s: str):

    res = 0
    s = s.replace("BC","D")
    s = [ conv2num(c) for c in s ]

    acnt = 0
    for i,c in enumerate(s):
        if c == 1:
            acnt += 1
        elif c == 2:
            res += acnt
        else:
            acnt = 0


    print(res)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

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

print(ans)

Solution (Python):
s=input()
numA = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'A':
        numA += 1
    elif i < len(s)-1 and s[i] == 'B' and s[i + 1] == 'C':
        ans += numA
    elif i > 0 and s[i] == 'C' and s[i - 1] == 'B':
        pass
    else:
        numA = 0
print(ans)

Solution (Python):
S=input().replace("BC","D").replace("B","C").split("C")
ans = 0
for s in S:
    a = 0
    for c in s:
        if c == "A":a+=1
        else:ans += a
print(ans)

Solution (Python):
s = input()

if len(s)<3:
    print(0)
    exit()

i = 0
while True:
    if s[i:i+2]=='BC':
        s=s[:i]+'D'+s[i+2:]
    i+=1
    if i>=len(s):
        break


s1 = s.split('B')
s2 = []
for i in range(len(s1)):
    s2+= s1[i].split('C')


ans = 0

for i in range(len(s2)):
    d = s2[i].count('D')
    for j in range(len(s2[i])):
        if s2[i][j]=='A':
            ans += d
        else:
            d-=1


print(ans)

Solution (Python):
s = input()

if len(s)<3:
    print(0)
    exit()

i = 0
while True:
    if s[i:i+2]=='BC':
        s=s[:i]+'D'+s[i+2:]
    i+=1
    if i>=len(s):
        break


s1 = s.split('B')
s2 = []
for i in range(len(s1)):
    s2+= s1[i].split('C')


ans = 0

for i in range(len(s2)):
    d = s2[i].count('D')
    for j in range(len(s2[i])):
        if s2[i][j]=='A':
            ans += d
        else:
            d-=1
            if d == 0:
                break

print(ans)

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

print(ans)

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

Solution (Python):



S = str(input()).replace("BC","D")

ans,stk = 0,0
for c in S:
  if c == "A":
    stk += 1
  elif c == "D":
    ans += stk
  else:
    stk = 0
print(ans)

Solution (Python):

s = input()
s = s.replace("BC", "X")
count = 0
a_stack = 0
for idx, char in enumerate(s):
    if char == "A":
        a_stack += 1
    elif char == "X":
        count += a_stack
    else:
        a_stack = 0
print(count)